Archived

This topic is now archived and is closed to further replies.

Multiple Users and Asynchronous Sockets

This topic is 5093 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, Just a quick question. Currently working on some type of decently large scale instant messaging program. But I''m damn confused. I understand the basics. Sending, receiving, accepting, etc..but, should I be say declaring a new object for each user online which holds the socket handle and other various information I may need? And then possibly store this list of objects in a linked list? Also, when the server receives an FD_READ message, how do I know which user, or socket, it was received from? Thanks, Mike

Share this post


Link to post
Share on other sites
I wrote a server that when it accepts a new connection it automatically creates a new user object. It then assigned a userID to each object as it was created and used the users socket as the value of the id. It also recieved the users specific object data using recvfrom() and copied the values to the objects variables. The objects also had a address struct in them that was filled with the address info captured by the recvfrom() method. Then it put the object in a linked list.

Also when using FD_SET you can use select() and have it select the sockets that are ready to be read. When you go through the list of all the sockets ready to be read they will contain the socket number telling you whos id number (using method above) sent the message.

Share this post


Link to post
Share on other sites