public bool StartNetworking() { IPAddress ipAddress = Dns.GetHostAddresses("192.168.2.16")[0]; /* // This section finds the local IP address. // This is only used when the server is on the same computer. IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName()); IPAddress ipAddress = null; foreach (IPAddress addr in ipHostInfo.AddressList) { if (addr.AddressFamily == AddressFamily.InterNetwork) { ipAddress = addr; break; } } */ clientSocket = new SocketHandler.Client(ipAddress, PORT); if (!clientSocket.isRunning) { Debug.LogError("Failed to connect to server"); clientSocket = null; return false; } clientSocket.onReceiveData += (m) => messageQueue.Enqueue(m); udp = new SocketHandler.UDPController(clientSocket.socket); return true; }
public void StopNetworking() { if (udp != null) { udp.Stop(); udp = null; } if (clientSocket != null) { if (clientSocket.isRunning) { clientSocket.Stop(); } clientSocket = null; } }