![](http://www.darkomenstudios.com/doslogo.jpg)
Handling Many Connections WinSock
Hey,
My question regards how to handle many simultaneous connections using WinSock.
Should I write a playerdata class, and inside of it have a socket for every player?
This is my first real delve into Network programming, and I wanted to setup some code that would allow me and several of my friends to connect and interact in a mud like environment.
I can do everything else, but the part involving how to handle many connections has stumped me.
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
quote:
Should I write a playerdata class, and inside of it have a socket for every player?
Yup, that''s how I''d do it. I think I''d probably write a socket class to buffer data and make sending and receiving a little easier, but it would still end up being a member of playerdata.
quote:
Original post by TheRealBartman
Should I write a playerdata class, and inside of it have a socket for every player?
You could, but I suggest you have a public UDP socket for login / server info that provides a connection ID upon login, and a private player socket (one for all players); you just pick up the sender''s IP from the receivefrom() call and update the player with the corresponding IP. IPs that become inactive after a few seconds can be marked as ''disconnected''.
-cb
Isn''t UDP fairly unreliable as far as packets arriving in the correct order etc?
Anyway, thanks for your guys help.
I have been sifting through the source of a few mud servers to see how they do it.
Does anyone know of a mud codebase that has well documented code and is easy to follow?
Thanks,
Michael Bartman
Anyway, thanks for your guys help.
I have been sifting through the source of a few mud servers to see how they do it.
Does anyone know of a mud codebase that has well documented code and is easy to follow?
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
quote:
Isn''t UDP fairly unreliable as far as packets arriving in the correct order etc?
Yeah, there''s no guarantee that UDP datagrams will arrive in the correct order, assuming they arrive at all. On the other hand, UDP maintains record boundaries and offers less overhead. Both protocols have their uses, however, I believe TCP makes much more sense in your case.
quote:
I have been sifting through the source of a few mud servers to see how they do it.
The servers I''ve seen tend to be written for Unix, use TCP for the protocol, maintain a socket for every player in the game, and use select() to get around the blocking issue.
quote:
Does anyone know of a mud codebase that has well documented code and is easy to follow?
Most of them don''t seem to be particularly well documented, seeing as how they''re usually pet projects that get hacked together. You could try looking at the ROM code base. If I recall correctly, all of the networking code was in comm.c.
Yeah, I thought about rom, but I had already peeked at smaug and they are both derivitives of the same codebase :/
So they are in many ways the same.
I have found that a combination of looking to Beej''s Networking Guide and debugging the Smaug Mud Codebase while players connect has been very helpful.
Already, I have a custom chat server that can accept unlimited clients, every client can enter their chat handle, it will soon be compatible with Telnet so that it the server does not send every single letter that the client types.
What I mean is that telnet sends everything that is typed in one letter at a time. Thus, on the servers side, the client struct will need some sort of buffer for the clients input. Once the input is ''\0'', or null terminated, then it will process what the client has entered.
I love multiplayer programming :D It feels like back when I first started programming, all over again and just as exciting.
Thanks for all of your help, I may need it again soon though
,
Michael Bartman
So they are in many ways the same.
I have found that a combination of looking to Beej''s Networking Guide and debugging the Smaug Mud Codebase while players connect has been very helpful.
Already, I have a custom chat server that can accept unlimited clients, every client can enter their chat handle, it will soon be compatible with Telnet so that it the server does not send every single letter that the client types.
What I mean is that telnet sends everything that is typed in one letter at a time. Thus, on the servers side, the client struct will need some sort of buffer for the clients input. Once the input is ''\0'', or null terminated, then it will process what the client has entered.
I love multiplayer programming :D It feels like back when I first started programming, all over again and just as exciting.
Thanks for all of your help, I may need it again soon though
![](smile.gif)
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
quote:
What I mean is that telnet sends everything that is typed in one letter at a time. Thus, on the servers side, the client struct will need some sort of buffer for the clients input. Once the input is ''\0'', or null terminated, then it will process what the client has entered.
That''s the right way to do it, even if you aren''t using Telnet. Because TCP is a streaming protocol, it can break up your packets so that you may have to call recv() multiple times, even if the client only called send() once. Alternatively, the client could have its send() calls buffered by WinSock, so that your server gets two whole lines of input in one call to recv(). It gets a bit confusing sometimes.
Anyways, it sounds like you''ve got it under control. Have fun!
Thanks Matt!
I am having a lot of fun playing with sockets, it is a whole different side to game programming that I''ve never really toyed with.
Michael Bartman
I am having a lot of fun playing with sockets, it is a whole different side to game programming that I''ve never really toyed with.
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
quote:
Original post by TheRealBartman
it will soon be compatible with Telnet so that it the server does not send every single letter that the client types.
Coooool. One stupid question though. Do you handle those nifty OOB messages that TELNET sends when the client sends a CTRL-something?
-cb
It will ignore those
I can't think of why you would use those in a mud environment, which is what I am going to eventually develop. Also, most mud players don't use telnet because of it's lack of features.
Edit:
Actually, it doesn't ignore them; It takes it as a valid character and puts it in the buffer. All just by recv()'ing it.
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
[edited by - TheRealBartman on March 11, 2003 11:58:14 PM]
![](tongue.gif)
Edit:
Actually, it doesn't ignore them; It takes it as a valid character and puts it in the buffer. All just by recv()'ing it.
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
[edited by - TheRealBartman on March 11, 2003 11:58:14 PM]
Michael BartmanLead ProgrammerDark Omen Studios
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement