//连接 public void Connect() { try { Debug.Log("尝试连接:" + IP + ":" + Port); this.socket = new TcpClient(); this.socket.Connect(Url, Port); SetSocket(); client.SuccessInfo(); Debug.Log("连接成功..."); } catch (SocketException e) { client.ErrorInfo(GlobalData.NET_MSG_Try); Debug.Log("连接中断,2秒后重连..." + e); //重连 Thread.Sleep(2000); this.Connect(); } catch (Exception e) { Debug.LogError("连接错误:" + e); } }
//连接 public void Connect() { try { Debug.Log("尝试连接:" + IP + ":" + Port); this.socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); this.socket.Connect(IP, Port); Debug.Log("远程EndPoint:" + socket.RemoteEndPoint.ToString() + " 本地EndPoint:" + socket.LocalEndPoint.ToString()); SetSocket(); client.SuccessInfo(); Debug.Log("连接成功..."); }catch (SocketException e) { client.ErrorInfo(GlobalData.NET_MSG_Try); Debug.Log("连接中断,2秒后重连..." + e); //重连 Thread.Sleep(2000); this.Connect(); } catch (Exception e) { Debug.LogError("连接错误:" + e); } }