![](http://www.darkomenstudios.com/doslogo.jpg)
Question on Server Logic
Hey all,
I am writing a MUD-type game Server.
I know that a mud server must accept connections and run game logic in a continuous loop. However, I am using select based sockets, and the loop pauses at the select call.
Naturally, I assumed that this meant I should use multithreading. I am thinking that I will need a primary logic thread, and a thread for recieving and accepting connections.
Would I need to make a list of some sort that the recieve/accept thread uses to tell the main thread that a player has pushed enter and is ready to have whatever they have typed in parsed. Then the main loop would read that message in the list, and goto that player and process their buffer?
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
Actually, you''ve most likely set the
Instead, you can just pass in a 0
codeka.com - Just click it.
timeout
parameter to NULL. Doing so will make the select
call block until something arrives on one of the descriptors.Instead, you can just pass in a 0
timeval
struct, which will mean the call to select
will return 0 if there isn''t any data waiting (or the number of descriptors which have data waiting if it returns anything other than SOCKET_ERROR). If I had my way, I''d have all of you shot!
codeka.com - Just click it.
Thanks,
but I have a question about that too:
If I set the timeout parameter to 0, there won''t be a possibility for missing data or connections if my logic loop happens to take large amount of time?
Thanks,
Michael Bartman
but I have a question about that too:
If I set the timeout parameter to 0, there won''t be a possibility for missing data or connections if my logic loop happens to take large amount of time?
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
Setting it to 0 is the same as setting it to null, so I made an instance of the timeval struct and set that up. It now works properly, without multithreading.
One last question, what is the best time I should set the timeval to?
Michael Bartman
One last question, what is the best time I should set the timeval to?
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
0s 0ms
Your logic loop better not take more than a few milliseconds, so don''t worry about it getting hung up there.
Your logic loop better not take more than a few milliseconds, so don''t worry about it getting hung up there.
NULL
and a 0 timeval are different. Setting it to NULL
gives you an "infinite" timeout, while passing in a zero''d timeval
will give you no timeout.Assuming you''re using TCP then it won''t matter how long your main loop takes, because TCP uses what''s called the "sliding window" algorithm to ensure that the client won''t send more data than the server has buffer space for. So if the servers buffer space fills up, the client won''t send any more data until you take some off the buffer (by calling
recv
). If I had my way, I''d have all of you shot!
codeka.com - Just click it.
if you go with multi-threaded when you get a new connection on the connection thread put that connection into a array and mark that connection as in use. the game thread will walk through all the connection looking for those that are in use. when someone disconnects from the server, the game thread will mark it not in use so that the connection thread can use it again.
I already have a linked list made out of structs called CharData, that wasn''t the problem for me ![](tongue.gif)
Dean, I misread what you originally posted; I thought you said to set the timeout paramter to 0, I missed when you said timeval lol Sorry about the misunderstanding, I ended up doing what you said anyway.
Thanks,
Michael Bartman
![](tongue.gif)
Dean, I misread what you originally posted; I thought you said to set the timeout paramter to 0, I missed when you said timeval lol Sorry about the misunderstanding, I ended up doing what you said anyway.
Thanks,
Michael Bartman
![](http://www.darkomenstudios.com/doslogo.jpg)
Michael BartmanLead ProgrammerDark Omen Studios
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement