[Help]SocketConnection 5290+

02/11/2011 12:33 Mr_PoP#1
Code:
int main()
{
	CRc5 dec;
	WSADATA wsaData;
	int err;
	if((err =WSAStartup(0x0002, &wsaData)) !=0)
	{
		printf("Init WSAStartup() failed[%d].", err);
		return false;
	}
	//socket structure
	SOCKADDR_IN addr;//addr = socket structure
	int addrlen = sizeof(addr);

	//making the socket
	SOCKET sListen;//listenig to the incoming connections
	SOCKET sConnect;//operating the connection

	//setuping the socket
	sConnect=socket(AF_INET,SOCK_STREAM,NULL);//sock_stream = that the socket is a connection_oriented

	//setup the structure
	addr.sin_addr.s_addr=inet_addr("127.0.0.1");// ip of the connection
	addr.sin_family= AF_INET;
	//seting the prot
	addr.sin_port= htons(9958);

	//sertuping Listen socket
	sListen=socket(AF_INET,SOCK_STREAM,NULL);
	//binding connection
	bind(sListen,(SOCKADDR*)&addr,sizeof(addr));
	//listening 
	listen(sListen,SOMAXCONN);//listing with out any limit
	printf("Attempting Socket Connection\n");
	printf("Wating For An Incoming Connection!\n");
	for(;;)
	{
		if((sConnect=accept(sListen,(SOCKADDR*)&addr,&addrlen)) != INVALID_SOCKET)
		{
			char buf[500];
			int len = strlen(buf);
			recv(sConnect,buf,len,0);
			
		}
		else
		{
			printf("Error accepting %d\n",WSAGetLastError());
		}
	}
}
but it's not receiving anything it's accepting the socket and then nothing happend why!!?
02/11/2011 13:08 { Angelius }#2
Quote:
addr.sin_port= htons(9958);
i thought the port must be 9959 am i right ?

oh and btw take a look at this thread it might help you .
[Only registered and activated users can see links. Click Here To Register...]
02/11/2011 13:36 Mr_PoP#3
Quote:
Originally Posted by { Angelius } View Post
i thought the port must be 9959 am i right ?

oh and btw take a look at this thread it might help you .
[Only registered and activated users can see links. Click Here To Register...]
yeah it's 9959 but am working with 9958 , Immunes is c# mine is c++
02/11/2011 14:53 S/W#4
Quote:
Originally Posted by Mr_PoP View Post
yeah it's 9959 but am working with 9958 , Immunes is c# mine is c++
C# or c++ port should by 9959.
02/11/2011 14:57 Korvacs#5
The port can be whatever you want aslong as you remember to change the conquer.exe to suit the new port.
02/11/2011 15:06 © Haydz#6
Code:
			int len = strlen(buf);
			recv(sConnect,buf,len,0);
->
Code:
recv(sConnect, buf, 500, 0);
You've initialized a buffer of 500 bytes, but the string length is 0.

I have a kind of minor OCD complex with buffer sizes, and tend to always use multiples of 512 :D

Nice to see abit more c++ here anyway.
02/11/2011 15:10 Basser#7
This is completely patch / conquer unrelated.
02/11/2011 15:37 Mr_PoP#8
Quote:
Originally Posted by S/W View Post
C# or c++ port should by 9959.
Quote:
Originally Posted by Korvacs View Post
The port can be whatever you want aslong as you remember to change the conquer.exe to suit the new port.
Exactly :)

Quote:
Originally Posted by © Haydz View Post
Code:
			int len = strlen(buf);
			recv(sConnect,buf,len,0);
->
Code:
recv(sConnect, buf, 500, 0);
You've initialized a buffer of 500 bytes, but the string length is 0.

I have a kind of minor OCD complex with buffer sizes, and tend to always use multiples of 512 :D

Nice to see abit more c++ here anyway.
i did wat u said but still it's not accepting to recv() <<< when it comes there it's like the program stop working but while am in infinity loop the program doesnot close , I appreciate ur help , please if there something else i missed or something i should add tell me thnx

Quote:
Originally Posted by Basser View Post
This is completely patch / conquer unrelated.
what are u talking about?!
02/11/2011 15:48 © Haydz#9
Code:
WSAStartup(0x0002, &wsaData)) !=0)
Needs to be 0x202, instead of 0x0002.
Code:
sListen=socket(AF_INET,SOCK_STREAM,NULL);
Didn't even notice this but, it needs to be IPPROTO_TCP instead of null

Verified this for you on my side, and is working correctly.
02/11/2011 16:02 Mr_PoP#10
Quote:
Originally Posted by © Haydz View Post
Code:
WSAStartup(0x0002, &wsaData)) !=0)
Needs to be 0x202, instead of 0x0002.
Code:
sListen=socket(AF_INET,SOCK_STREAM,NULL);
Didn't even notice this but, it needs to be IPPROTO_TCP instead of null

Verified this for you on my side, and is working correctly.
i did that and still it's not working look it works for (5017-5100+) but like 5200+ it's not , look try to test it on a Client patch 5295 u will see what am talking about :)
02/11/2011 16:08 © Haydz#11
Quote:
Originally Posted by Mr_PoP View Post
i did that and still it's not working look it works for (5017-5100+) but like 5200+ it's not , look try to test it on a Client patch 5295 u will see what am talking about :)
Because on those later client's you send them the password seed, before they send you anything.
02/11/2011 16:17 Mr_PoP#12
Quote:
Originally Posted by © Haydz View Post
Because on those later client's you send them the password seed, before they send you anything.
i know am being mean but can u give me an Exmaple :) if u dont mind

Edit: what do u think using C++/CLI (socket) better or the normal WinSock?
02/11/2011 16:55 pro4never#13
I've posted the packet example in a bunch of different forums...

Recent patches use the new password encryption which requires a password seed. The client does not send any packets until it receives this packet.

It's only 8 bytes (length, type and then a random int pass seed)
02/11/2011 16:57 Nullable#14
You can't mix C++/CLI code with native C++ code normally, and to do so you'd have to go through loads of code.
You can't use the current code to send a password seed packet either, you have to construct the packet and encrypt it with the auth crypto then send() it.
02/11/2011 18:41 -impulse-#15
Quote:
Originally Posted by Nullable View Post
You can't mix C++/CLI code with native C++ code normally, and to do so you'd have to go through loads of code.
You can't use the current code to send a password seed packet either, you have to construct the packet and encrypt it with the auth crypto then send() it.
Or, since the auth crypto doesn't use a public key and it has just a 255 bytes which it uses to encode/decode buffers, you can simply calc it once, and just make a const buffer that needs to be sent.