2
\$\begingroup\$

My use of terminology may be off a little bit. I have been playing around with the Lidgren XNA sample for how the library works, and it is simple to implement it looks like.

I am curious on the logic or theory behind making the game client also act as a server? Basically I want a user to open the game client and have the option of "Hosting a Game" which would allow others to connect to that computer and play multiplayer.

It was suggested that I use some sort of thread to kick off the server code in the background for that host client and then connect the two pieces together for full functionality.

\$\endgroup\$
  • 1
    \$\begingroup\$ "It was suggested that I use some sort of thread to kick off the server code in the background for that host client and then connect the two pieces together for full functionality." This is exactly how hosting your own game should work. Just a second thread or a new process on the host's machine that he can then join himself as well. \$\endgroup\$ – Roy T. Mar 15 '12 at 20:01
  • \$\begingroup\$ Thanks Roy, I was just unsure if that is exactly what I need to be looking for. I have found in the past I think I am researching what I need, but in fact the process I am trying to complete has a more specific name. When I was trying to find code for client / server networking, I was blissfully ignorant of the client server part of that statement. \$\endgroup\$ – sec_goat Mar 15 '12 at 20:07
  • \$\begingroup\$ @RoyT. you should make that answer. sec_goat what Roy said is exactly how ID (Quake, Doom, etc.) does things and it works really well for them: you simply reject connection from anything other than 127.0.0.1 for single player mode; or if you can abstract your network layer under an abstraction layer you can write a link-local socketless implementation. \$\endgroup\$ – Jonathan Dickinson Mar 16 '12 at 9:13
  • \$\begingroup\$ Jonathan, thanks for that answer, I would mark his comment as the answer but I don't think I can. Still A little new here. Thank you for giving me some things to think about, a lot of times if I have some idea of what I am trying to do, terminology-wise, I can end up finding my way to the solution. \$\endgroup\$ – sec_goat Mar 16 '12 at 12:24
  • \$\begingroup\$ Jonathan Dickinson: at first I thought it was too short for a real answer but since no-one else posted an answer yet I followed your advice. \$\endgroup\$ – Roy T. Mar 16 '12 at 19:03
1
\$\begingroup\$

This is a quote of my comment earlier so this question can be resolved:

"It was suggested that I use some sort of thread to kick off the server code in the background for that host client and then connect the two pieces together for full functionality." This is exactly how hosting your own game should work. Just a second thread or a new process on the host's machine that he can then join himself as well.

\$\endgroup\$
  • \$\begingroup\$ So far so good with this theory. I have a client that also kicks off the server portion and all is well. Need to flesh out the code a little more, but just hearing the idea behind what I need to do helps a lot. Thanks! \$\endgroup\$ – sec_goat Mar 21 '12 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.