Archived

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

kalldrex

Winsock sockets.....

Recommended Posts

Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
(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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
quote:
Original post by Magmai Kai Holmlor

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.


UO does not use UDP... It uses TCP. If you want to bet --- I'll gladly take your money, if you have any.

I goofed and placed a /IP at the end of TCP - You are correct in what you say about TCP/IP - it is a set or a suite of defined protocols that applications use to connect peer-peer or peer-server.

TCP is one of the protocols. It is a connecion oriented protocol and provide reliability- meaning that verifies data arrives and automatically retransmits segments that do not. It computes checksums to gaurantee uncorrupted data and it sequences numbers to provide ordered data arrival and it provides flow control to make sure that the client does not send more data than the server can process it.

UDP is another protocol. It is connectionless and does not provide any reliability. Does not gaurantee deliver does not validate data, does not sequence numbers to provide ordered data arival and does not care about flow control. It is fast - but it is dependent on the underlying network (the internet in this case) more so than TCP is. Therefore packet loss is alomst gauranteed.

Myself and others have designed there own UDP w/ reliability added. If you going to use UPD over the internet, then you need to have some level of reliability added to the protocol.

As for determining who to send messages to - Magmai is right. You need to determine the proximity of players to events in you games and send out messages to the players who need to be told. There are many different ways of determining who to send messages to. A simple Pythagorean might work for you:
http://www.pbs.org/wgbh/nova/proof/puzzle/theorem.html
or you may need to do something based on zones - as I said there are several ways that you can use to make this determination.




Game On,

Edited by - Dak Lozar on February 8, 2001 8:48:08 PM

Share this post


Link to post
Share on other sites