🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Non-Blocking Sockets vs. 2 Threads. (UDP)

Started by
3 comments, last by phueppl1 23 years, 1 month ago
Hi There! I''m writing an UDP server at the moment. It''s supposed to handle a MMORPG, so there''ll quite a lot of connections. Now, since I''m using UDP I''ll have to sort messages and kinda put them on a stack or something. They way I implemented it now, is that I got a thread the calls recvfrom(); all the time and sorts the received package onto the stack of the connection. Then the other thread just works of the messages from the stack. Now I wonder, would it be cleverer to put them together in one thread and make the socket non-blocking or is it ok to have 2 threads? The way I''m thinkin'' about that right now, is that I''ll stick to the 2 threads, cause it''ll use dual processor systems if available (I hope and then the 2 threads will split up fairly well. (I''ll have another thread to handle the world/AI and other game stuff, but that''s another story .. Ok, tell me what you think ''bout that.. thx, cya, Phil Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
Advertisement
quote: Original post by phueppl1
Now, since I''m using UDP I''ll have to sort messages and kinda put them on a stack or something.


I would suggest a queue; first in first out...stacks are first in last out...might not work out too well for yah wiht a stack.

quote: Original post by phueppl1
They way I implemented it now, is that I got a thread the calls recvfrom(); all the time and sorts the received package onto the stack of the connection. Then the other thread just works of the messages from the stack. Now I wonder, would it be cleverer to put them together in one thread and make the socket non-blocking or is it ok to have 2 threads?


I see with no problem with 3 threads (main thread and 2 networking threads); Windows should only give each thred the processor power it needs…or at least it should if it doesn''t! I thought about doing this then got to thinking…hey I don''t have high bandwidth so the amount of data I''m sending over the net is minimal. I figured the game will be running at 30+ fps so the gap between frames updates to the server is not that bad. Since I don''t need to have *that* much info going out I deticated only a little part to my thread that sends stuff out (MAYBE 2 packets most likely 1 per every 3 frames); most of my data is comming in…no need to add in another thread, but yours might be different.


Hope this helps…if not sorry

Regards,
ecko_53




———————————————————–
"People who usualy use the word pedantic usualy are pedantic!"-me
-----------------------------------------------------------"People who usualy use the word pedantic usualy are pedantic!"-me
I think they way you''re doing it is the right way. Remember, since UDP is unreliable, when the underlying buffer fills up, additional packets are dropped. So if you expect to be recieving packets constantly and have a decent amount of processing to do per packet you''re much less likely to lose packets with a dedicated recv thread.
ok! thx!

What I meant with Stack was actually a Buffer, so... (A Linked List and is sorted by the 2 byte index I send with every package as an index. lowest one first. So you think I''m doing fine oki... great!

cya,
Phil

Visit Rarebyte!
and no!, there are NO kangaroos in Austria (I got this questions a few times over in the states
Visit Rarebyte! and no!, there are NO kangaroos in Austria (I got this question a few times over in the states ;) )
Does anyone have that win2k server netmon utility that they could send me? My email address is idekine@acedsl.com

Thanks.

This topic is closed to new replies.

Advertisement