Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualcrancran

Posted 20 December 2012 - 12:42 PM

To add to what hplus0603 said, if you put your network connection into non-blocking mode, you can use select() and poll for data each loop and handle it accordingly. In a well structured design, networking really should be abstracted away to the point that if you decide to move networking to a separate thread later on, the impact to the simulation would be very minimal and non-invasive to change.

But if you want to use a separate thread, you can use asynchronous/non-blocking socket IO to handle reads/writes in a single thread outside your logic thread. This way the problem manifests itself to a simple problem of synchronizing a queue of messages between the logic/network threads for sending/receiving. But in most cases, this isn't really necessary and by avoiding it reduces the complexity of your game logic iterations.

#2crancran

Posted 20 December 2012 - 12:41 PM

To add to what hplus0603 said, if you put your network connection into non-blocking mode, you can use select() and poll for data each loop and handle it accordingly. In a well structured design, networking really should be abstracted away to the point that if you decide to move networking to a separate thread later on, the impact to the simulation would be very minimal and non-invasive to change.

But if you want to use a separate thread, you can use asynchronous/non-blocking socket IO to handle reads/writes in a single thread. This way the problem manifests itself to a simple problem of synchronizing a queue of messages between the logic/network threads for sending/receiving.

#1crancran

Posted 20 December 2012 - 12:40 PM

To add to what hplus0603 said, if you put your network connection into non-blocking mode, you can use select() and poll for data each loop and handle it accordingly. In a well structured design, networking really should be abstracted away to the point that if you decide to move networking to a separate thread later on, the impact to the simulation would be very minimal and non-invasive to change.

PARTNERS