I've made a multiplayer game using a TCP connection. Although there isn't any lag when I run the server and client on the same computer, my friends say it lags quite bad on their computer(which is to be expected). Would I benefit from converting from a TCP connection to a UDP connection?
And if so is it a quick matter of changing a few lines of code in the set up function?
It uses less network bandwidth, so it will be faster. And as you're always sending out updates from the server, it doesn't really matter if the odd packet or so doesn't arrive or arrives malformed. You may have firewall issues though.
To go from a TCP server to a UDP server:
1. Call socket() with IP Protocol id. Windows has a constant for which I can't recall right now, but generally you'd call getprotobyname("udp") to get the protocol.
2. You still call bind() so clients can find you.
3. Don't call listen()/accept(), just call recvfrom() in a loop.
To go from a TCP client to a UDP client:
1. Call socket() as you do for the server.
2 Don't call connect(), just start sending stuff with sendto().
? and if so how do I know when a player has joined and left? And how do I set up player Sockets on the server side?
normally I would use this in FD_ACCEPT; playerVector.back().socket=accept(wParam,&sockAddrClient,&size);
WSAAsyncSelect can be used for UDP and TCP read/write. All you have to do is handle the window messages and you will be fine
MSDN "The WSAAsyncSelect function is used to request that WS2_32.DLL should send a message to the window hWnd when it detects any network event specified by the lEvent parameter. "
Ok, I've almost mastered this. Although the server is picking up that something is being sent it's says that there's nothing in szIncoming. To get over the problem of it not detecting when a new client connects I've made the client send an "a" to the server like this;