public async void UDPTryConnect() { ILog rsp = UDPRemoteEndPoint.Initialize(); if (rsp != null) { rsp.Print(); return; } udpClient = new UDPClient(SimulationClient, UDPRemoteEndPoint.LocalPort, UDPRemoteEndPoint, UDPClientState, ContextHandler); Debug.Log("[UDP] Connecting"); // this blocks but the main thread still goes on so Unity continues as normal rsp = await udpClient.Connect(); if (rsp != null) { rsp.Print(); return; } Debug.Log("[UDP] Connected"); rsp = await udpClient.Listen(); if (rsp != null) { rsp.Print(); return; } Debug.Log("[UDP] Disconnected"); }