Skip to main content
GameDev.net gamedev.net
🔒 Locked

Winsock Problem!

Started by Zwingling Sep 7, 2010 at 4:31 AM 2 replies 950+ views
Original Post
Zwingling
Zwingling
I started with Winsocket yesterday.
The server and client App. works perfectly on one computer, but if i try to connect from my Laptop to my Desktop Pc i don#t get any connections.

Could it be that the diffrent Operating-Systems are the reason.
My Desktop Pc os: Windows 7!
My Laptop os : Windows XP!

Could use some help :)
Evil Steve
Evil Steve
What exactly do you mean you "don't get any connection"? accept() never returns?

How are your laptop and desktop connected? Have you opened the port on the Windows firewall on the desktop? Have you tried using Wireshark to see if any packets are sent / received?
Zwingling
Zwingling
Yeah accept never returns.
i connected them with a LAN-cable also tried it with a hub.
I kicked both firewalls.
and yes wireshark gets pack.

here is the cpp code:

Client & Server
/////////////////////////////////////////////////////////////////////

int main()
{

WSADATA WsaDat;

if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)

{

printf("WSA Initialization failed.");

}
else printf("WINSOCKET is Initializet successful\n\n");

SOCKET Socket;

Socket=socket(AF_INET,SOCK_STREAM,NULL);


if(Socket==INVALID_SOCKET) printf("SOCKET failed.");
else printf("Socket INIT successful\n\n");


sockaddr_in sockAddr;

sockAddr.sin_family = AF_INET;
sockAddr.sin_port =50;
sockAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");



if(bind(Socket,(SOCKADDR*)&sockAddr,sizeof(sockAddr))==SOCKET_ERROR) printf("Error Binding\n\n");
else printf("Binding sucessfull\n\n");


if(listen(Socket,1)==SOCKET_ERROR) printf("Error with Listing\n\n");
else printf("Socket is Listining\n\n");

printf("Server is weiting for Clients.......\n");
printf("Run Client Programm!!\n\n");


SOCKET TempSocket=0;

while(TempSocket==0)
{

TempSocket=accept(Socket,NULL,NULL);
}

Socket=TempSocket;

printf("Client is connected");


system("PAUSE");

return 0;
}





////////////////////////////////////////////////////////////////////////////////


int main()
{

printf("WINSOCK TUT\n\n\n");



WSADATA WsaDat;

if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)

{

printf("WSA Initialization failed.");

}
else printf("WINSOCKET is Initializet successful\n\n");

SOCKET Socket;

Socket=socket(AF_INET,SOCK_STREAM,NULL);


if(Socket==INVALID_SOCKET) printf("SOCKET failed.");
else printf("Socket INIT successful\n\n");


sockaddr_in sockAddr;

sockAddr.sin_family = AF_INET;
sockAddr.sin_port =50;
sockAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");



connect(Socket,(SOCKADDR*)&sockAddr,sizeof(sockAddr));






system("PAUSE");






return 0;
}











Evil Steve
Evil Steve
On the server, you're binding to 127.0.0.1 - that tells it to only accept connections from that IP.

You want to use:
sockAddr.sin_addr.S_un.S_addr = INADDR_ANY;

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.