//private const int _bufferSize = 512; /// <summary> /// 临时用,建立tcp连接 /// </summary> /// <param name="ipAddressPort"></param> public void Connect(IpAddressPort ipAddressPort) { try { _ipAddressPort = ipAddressPort; _tcpClient = new TcpClient(); _tcpClient.Connect(ipAddressPort.HostName, ipAddressPort.Port); if (_tcpClient.Connected) { HaveConnected = true; byte[] buffer = new byte[_bufferSize]; _tcpClient.Client.BeginReceive(buffer, 0, _bufferSize, 0, new AsyncCallback(RecvEndCallBack), buffer); //if (OnConnectServSuccess != null) // OnConnectServSuccess(this, new ConnectEventArgs(SerMode, this, ipAddressPort)); } } catch (Exception e) { LogUtilities.LogMessage(this.SerMode.ToString() + "服务器连接失败..." + e.Message); } }
///<summary> ///</summary> ///<param name="tcpConnection"></param> ///<param name="ap"></param> ///<param name="reason"></param> public ConnectFailEventArgs(TcpConnection tcpConnection, IpAddressPort ap, String reason) { TcpConnection = tcpConnection; Ap = ap; FailReason = reason; }