Advertisement

Datagram sockets and recieving data

Started by January 17, 2004 01:31 PM
1 comment, last by Jasten 21 years ago
Hello, Im currently working on a client server networking setup for my senior project here at Full Sail in Orlando, FL. We will be creating a capture the flag type game that will require quite a bit of network activity. I have gone through and learned the basics of socket programming but I have a few questions for the experts out there as I build the client/server setup. Background of the design so far: I plan to utilize threads within the server to handle each client. Each client will have its own stream socket for the sending and recieving of chat. Additionally, each client will have a datagram socket for communicating all game packets. Now for the questions: Will I need to create a datagram socket for each client on the server, or can one socket recieve from multiple clients? From what I have gathered from the vague tutorials out there is that I must have a stream socket for each client on the server since they are "connected sockets" however im not sure where that leaves the connectionless sockets. Im also needing some clerification on how exactly the recvfrom works. I understand that you call the function with a buffer to recieve the data, but what im unsure of is what happens if multiple messages arrive at the same time? Does the socket queue them up so that after reading one message another may be read? I would appreciate any suggestions or comments. Thanks, Daniel Doptis DDoptis@fatesforgiven.com
"Will I need to create a datagram socket for each client on the server, or can one socket recieve from multiple clients?"

The server will only have one datagram socket that all clients communicate with. You can differentiate packets by the ip and the port that they were sent from. That info will be filled out in a sockaddr struct when you call recvfrom.

In each call to recvfrom, youll get back one full packet that was sent with sendto on the sending side. another call to recvfrom will get the next full packet, etc.

-=[ Megahertz ]=-

-=[Megahertz]=-
Advertisement
Thanks for the reply.

Daniel Doptis

This topic is closed to new replies.

Advertisement