Multiple Users and Asynchronous Sockets

Started by
5 comments, last by bower12345 20 years, 3 months ago
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
Mikehttp://cs.wpunj.edu/~bowersom
Advertisement
The message created by WSAAsyncSelect() on a network event will pass the socket as the wParam.
Why not sent the senders ID(or name) with the message?

struct Package{
long Sender;
unsigned char Data[256];
};

--
You''re Welcome,
Rick Wong
- sitting in his chair doing the most time-consuming thing..
recvfrom (or WSARecvFrom) will return the address of the sender of the data along with the data.
-Mike
Thanks SiCrane...that was what I was looking for. Can I use wParam directly in a recv() call or do I have to explicitly assign it and cast it to a SOCKET type?

Thanks,
Mike
Mikehttp://cs.wpunj.edu/~bowersom
You should be use it directly. (Though putting in a cast might be a good idea as a sort of comment.)
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.

This topic is closed to new replies.

Advertisement