Winsock

Started by
4 comments, last by hplus0603 17 years, 6 months ago
I coded a server program and a client program. I open the server program, then the client program. The server then finds the client and everything works. For now this is only working on one computer. I gave this client program to one of my friends and it didn't connect. I assume its an IP adress problem. The adress in the client program is from running ipconfig. Any help?

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Advertisement
If your pc is connected to a router the ip shown in ipconfig is not the right to use. In this case you can get your extern ip address for example from this address: http://whatismyipaddress.com/

It's also possible that your firewall doesn't allow this connection.
Yea my friend noted that, about the router ip. I used the router ip and it still doesnt work. And the firewall asks and I told it to allow the connection. The only error codes I'm getting on the client side are "connection timeout". My server never finds the client.

Client
------
sock.sin_family = AF_INET;
sock.sin_addr.s_addr = inet_addr("67.183.129.218");
sock.sin_port = htons(5001);

sendSock = socket(AF_INET, SOCK_STREAM, 0);
connect(sendSock, (SOCKADDR*)&sock, sizeof(sock));



Server
------
sock.sin_family = AF_INET;
sock.sin_addr.s_addr = INADDR_ANY;
sock.sin_port = htons(5001);

sendSock = socket(AF_INET, SOCK_STREAM, 0);
bind(sendSock, (SOCKADDR*)&sock, sizeof(sock) );
listen(sendSock, SOMAXCONN);

while(Client == INVALID_SOCKET)
{
Client = accept(sendSock, NULL, NULL);
}

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

If you have a router, you need to tell it to forward that port to your computer. I don't know the details of how to do that (it will be part of your router config and may well be router-dependent) – if anyone does, though, it's this forum!
Hell yea. It works. Does anyone know if I can do port forwarding in winsock. I ask because, say I have a person run a game and broadcasts to see if another game started. If he doesnt find a server, then I need to make him the server.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

The Forum FAQ talks about NAT punch-through, which is the only way you can host a game inside a firewall without explicit port forwarding. Note that it requires a collaborating matchmaker host that doesn't have a firewall.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement