private void startTCP() { if (!isStartTcp) { LogTool.Log("服务器连接成功" + serverPoint); asyncTcpClient = new AsyncTcpClient(); asyncTcpClient.Connet(serverPoint); asyncTcpClient.OnReceived += AsyncClientReceived; isStartTcp = true; } }
// Update is called once per frame void ClientConnect() { try { if (asyncTcpClient != null) { while (!asyncTcpClient.isConnected && asyncTcpClient.tcpClient.Poll(connectTime, System.Net.Sockets.SelectMode.SelectRead)) { Loom.DispatchToMainThread(() => asyncTcpClient.Connet()); Loom.WaitForSeconds(connectTime); count++; } if (count > exitTime) { count = 0; Loom.DispatchToMainThread(() => closeTCP()); } } } catch (Exception e) { throw e; } }