public static void Connect(IPAddress host) { if (Connected) { Disconnect(); } _client = new ThreadlessUdpNetworkClient(PORT, Processor); HostAddress = new IPEndPoint(host, PORT); _client.BeginRecieve(Recieve); if (Statistics.Log) { Statistics.Connections++; } }
/// <summary> /// Network consume loop. /// Reads in network data as it becomes available. /// </summary> /// <param name="result"></param> private static void Recieve(byte[] viewBytes) { //UnityEngine.Debug.Log("Network.Recieve"); // Recieve next transmitted data. _client.BeginRecieve(Recieve); if (Statistics.Log) { Statistics.TotalMessagesRecieved++; } // Restore and process the sent message. var restoredView = _contract.UnpackForRecieve(viewBytes) as View; if (restoredView == null) { return; } if (Statistics.Log) { Statistics.ValidMessagesRecieved++; } // Don't route our own messages. var loopBack = Equals(restoredView.SenderAddress, LanAddress); if (loopBack) { return; } ViewRouting.Route(restoredView); if (Statistics.Log) { Statistics.ForignMessagesRecieved++; } }