public void SynchronizeInputEventsAcrossAllNodes(ref List <VREvent> inputEvents) { // 1. send inputEvents to server VRNet.SendEventData(ref client, /*in*/ inputEvents); // 2. receive and parse serverInputEvents List <VREvent> serverInputEvents = new List <VREvent>(); VRNet.ReceiveEventData(ref client, ref serverInputEvents); // 3. inputEvents = serverInputEvents inputEvents = serverInputEvents; }
public void SynchronizeInputEventsAcrossAllNodes(ref List <VREvent> inputEvents) { // 1. FOR EACH CLIENT, RECEIVE A LIST OF INPUT EVENTS GENERATED ON THE CLIENT // AND ADD THEM TO THE SERVER'S INPUTEVENTS LIST // the following section implements something similar to a socket select statement. // we need to receive data from all clients, but socket 4 may be ready to send data // before socket 1, so we loop through the sockets reading from the first we find // that is ready to send data, then continue looping until we have read from all. // initialize list to include all streams in the list to read from List <int> toRead = new List <int>(clients.Count); for (int i = 0; i < clients.Count; i++) { toRead.Add(i); } // loop until the list of streams to read from is empty while (toRead.Count > 0) { int i = 0; while (i < toRead.Count) { if (clients[toRead[i]].GetStream().DataAvailable) { // if ready to read, read data and remove from the list of streams to read from TcpClient c = clients[toRead[i]]; VRNet.ReceiveEventData(ref c, ref inputEvents); toRead.RemoveAt(i); } else { // this stream not ready to read, move on to the next i++; } } } // 2. SEND THE COMBINED INPUT EVENTS LIST OUT TO ALL CLIENTS for (int i = 0; i < clients.Count; i++) { TcpClient c = clients[i]; VRNet.SendEventData(ref c, /*in*/ inputEvents); } }