Winsock sockets.....

Started by
9 comments, last by kalldrex 23 years, 2 months ago
for any multiplayer game i have to use one socket per client correct?
ALL YOUR BASE ARE BELONG TO US!!!!
Advertisement
No.

If you''re using UDP then all clients can talk to a single socket and you can send to any of them using sendto().

-Mike
Well i''m using UDP and it''s an MMORPG so i only want to send messages of one client to the others that are within a certain area and anyone out of the area won''t recieve info on that client. will i have to use multiple sockets for this? If so i may just have each map a different socket instead of a distance around.
ALL YOUR BASE ARE BELONG TO US!!!!
The anon poster said it correctly. One socket.

UDP/IP is connecionless, meaning there isn''t a connection as in TCP/IP. The server binds to a specific port on the host machine and all the clients are told what port that is. Then when a client talks to the server it really just throws a message out.

Here is an expample that may or may not help in explaining this.

TCP/IP is like when you call someone on the phone. You pick up the phone dial a number and wait for someone to answer. When your friend anwers - you can converse as long as there is a connection...

UDP/IP is like writing your friend a letter. You write the letter and carefully place the name and address on the envelope, carry the letter to the mailbox and place it inside. The postman picks it up for delivery - if he loses the letter the message is never read. If the letter does arrive, your friend responds to you in the same manner.

I know some of you are laughing at my example but way back in ''85 when I first started network programmin - I was told that by a wise old soul - it helped me visualize what was happening.

HTH, Game On,

Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
Even if you do use UDP you might want to distribute the load.

Putting 10,000 users on a single socket would flood the sockets message buffers.
------------------------------------------------------------I wrote the best video game ever, then I woke up...
So even though if i have like 100 users on one socket i can get and send information only to certian users? How exactly would i do this?

Also is the galileo guy correct about flooding the buffers?

Edited by - kalldrex on February 7, 2001 1:32:01 PM
ALL YOUR BASE ARE BELONG TO US!!!!
(I''m the anon guy at the top. I finally broke down and registered)

You receive a packet by calling recvfrom(). This gives you the packet plus the IP address of the client. You can send information to a specific client by calling sendto(). This takes the information packet and the IP address and sends it to just that one person. This is how you talk to multiple clients on a single socket.

To send to a particular group of people you typically need to do a sendto() for each one of them. There is something called multicast which lets you do it all in a single sendto() but it doesn''t really work over the Internet in general.

Having 10,000 users connecting to a single *machine* is going to be really hard, let alone a single socket. But yeah, if you''re not reading fast enough you will start to drop packets. You can increase the size of the socket buffer or use multiple sockets but this is really only useful to cover short-term spikes. If you''re not reading fast enough in general you''ll drop packets no matter how many sockets you''ve got.

-Mike
-Mike
Anon Mike, Congratulations on registering

Having 10,000 users connect to any server is nightmare - and 10,000 users communicating with a game server is nightmare on elm street
All of the big games (UO[TCP], AC[UDP-i think] and EQ[UDP] limit the number of users that can ''connect'' to their servers.

UO running under TCP/IP limits the count to around 2,500 users and AC and EQ typically have around 3k...

The big problem w/ STREAM (TCP) sockets is not that each socket takes up memory, which they do, but that you have to come up with a way to ''serve'' all of the request coming in on that socket. If you don''t do it in an efficient manner - lag is increased. The problem is dealing with the internet, lag is going to exist at some level so, you have to come up with ways to illiminate you causing it to be more noticable. Cubic splines and dead reckoning are some terms you will hear or read about the more interested you become in coding a MP game for the internet.

My advice is to come up with a way to limit the number of users that are connected... w/ TCP this is fairly simple keep a count of sockets created and when the MAX number of sockets have been created - don''t accept any more connects. On UDP, your protocol will probably have to include some loggin in communication and keep a linked list or better yet a tree of all connected IP addresses. when you receive a connection message add the user to the tree and increment your user counter - when you reach the max users don''t accept any more login request. As for why you keep a list of logged in users... well, when you receive a message on your socket, you probably want to store that message in a queue for another thread to process. When the 2nd thread plucks that message off the list, it checks the IP address to determine two things- one is the user logged in and 2 is he still logged in? What you do in either case is up to you...

Again the message protocol in UDP is important. Not to say that it isn''t in TCP but, in TCP you don''t have to keep messages in order like you would have to in UDP-

I''m probably going on and on... here but I''m trying to help. Let me know if you need any help and I will se what I can do.
Oh, if you haven''t written a server using TCP - I would give it a go first. Get comfortable with that and then move on to UDP - some of the knowledge will be transferable but, not all - UDP will make you lose your hair really fast....

Game On,



Dave "Dak Lozar" Loeser
Dave Dak Lozar Loeser
"Software Engineering is a race between the programmers, trying to make bigger and better fool-proof software, and the universe trying to make bigger fools. So far the Universe in winning."--anonymous
UO uses TCP/IP? Heh nowonder ti''s so laggy all the time and if you get timed out for like a few seconds you get disconnected.

Yes well our MMORPG is basically something me and 3 other friends are doing for fun (and we asked we get xtra credit in our programming class plus this other friend is CONVINCED that we can''t pull this off. heh we''ll show him lol). But especially at first we''re not going to have that many users. I think that we''ll wait and if it becomes real popular we''ll start looking for a publisher for advances and stuff so that we can get this but anyway. My point being we''re not going to have many people on it anyways so the socket overflow probably won''t occur. At the beginning it will basically be a few guys from our school.

I''m not quite sure how i would use the sendto() function really by sending different info to different clients. I know the game knows each client''s IP address but how would you resolve each client''s number and such. I"m not sure how to explain this really. I''m talking about like how to you program the sendto() to only send it to certain ip addresses and not others on the socket without changing the netcode?

Besides testing i pretty much understand UDP except for the sendto function.

heh and don''t worry about going on and on. I need help lol
ALL YOUR BASE ARE BELONG TO US!!!!
Of course UO uses TCP/IP!!! You will too! So will everyone else!

TCP/IP is a suite of protocols, one of which is UDP (another of whcih is TCP). I don''t know for certain that UO uses UDP, but I bet that it does.

Determining which client to send info too is not a exactly socket issue. In the game you need to determine who is near eachother and who is not, and keep some sort of list around containing who to send updates too.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara

This topic is closed to new replies.

Advertisement