Advertisement

Converting client/server from TCP to UDP...

Started by January 07, 2003 07:03 PM
4 comments, last by Illumini 22 years, 1 month ago
Main question I have has to do with the structure in general.... WIth my TCP multiclient server I wrote I did something like this Create a main listener sock and lets say 10 client socks, bind it to a port, make it listen. Check for connection attempts on listner, when one occurs have an open client sock accept the connection. The client sock can then send/recv with client. With UDP however it seems no accept a connection is needed... how does the server know which sock should recieve from which client? Just a general idea would help... I understand how a basic one client UDP server would work but what about multiple clients? Thanks in advance for you time and help.
With UDP, since your socket isn''t actually connected to anything on the server end you can receive the info from all your clients on one socket. The recvfrom function that you can use with UDP sockets not only gives you the packet, like recv, but it also gives you the address of the client you sent it to.

So, basically, you can receive all the stuff on one socket and then sort it out yourself based on the on the address it came from.

-John
- John
Advertisement
aight I was thinking it was something like that... Is this how big commercail online RPG''s handle it? I guess it just seemed like more data over one channel, but I guess it''s the same cause sockets are just virtual things heh.
Thought of another question heh.. If i identify the client by IP... what about users who are behind a router and both of them (on seperate comps) have the same public ip?

I was thinking since ill obviously need a handshake message that if recieved a handshake (even if its from a client address currently connected) that i''d spawn a new client.. But, what happens for other messages when I get a move command in from IP 234.23.43.156 and there are two clients with that IP? Does this mean all messages I send must include a usernumber as well? I can see this working with little trouble but the problem i see is if two users with same IP are trying to log in at the same time...
maybe it wont be a problem and im jsut imagining it.. But I''ll still take any extra insight in to the matter that anyone has.
You differentiate users by IP and port, if you have two users behind a router that NAT''s them they''ll have the same IP but NAT will shift the port number
Ah, that makes it alot easier. thanks again!

This topic is closed to new replies.

Advertisement