Winsock and UDP
I'm using nice simple MFC Socket commands with CAsyncSocket. I have sucessfully used it to create a server and client that connect through TCP and send data to eachother. What I want to do is use UDP. I understand that this is a connectionless protocol and unreliable. Well... i cant get to work at all.
Would someone be able to tell me the basic chain of events i have have to do to use UDP?
Since UDP is connectionless, things like Accept() and Listen() are meaningless, and so you use a different technique.
To initialise UDP, pass SOCK_DGRAM instead of SOCK_STREAM to CAsyncSocket::Create().
You can now use CAsyncSocket::SendTo and ReceiveFrom to send and receive between the client and server. You can also use CAsyncSocket::Connect on the client end to set the remote end address, and then use Send and Receive - but note that no connection is actually made; it's just setting defaults.
This means there is no way to decide whether the connection was dropped at some point (and therefore you lost a datagram); it's up to you whether the bandwidth increase is worth the risk. It's okay for streaming audio, for example, where dropouts are acceptable, but for reliable file transfer, you're better off sticking with TCP.