Exemple #1
0
 public void AsynConnect(string ip, ushort port, NormalCallBack connectBack, RecvCallBack recvBack)
 {
     SocketError      = SocketError.Success;
     this.connectBack = connectBack;
     this.recvBack    = recvBack;
     if (clientSocket != null)
     {
         if (clientSocket.Connected)
         {
             this.connectBack(false, SocketError.ConnectError, "Connect Repeat");
         }
         else
         {
             IPAddress  ipA   = IPAddress.Parse(ip);
             IPEndPoint point = new IPEndPoint(ipA, port);
             clientSocket.BeginConnect(point, ConnectCallBack, clientSocket);
         }
     }
     else
     {
         clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         IPAddress    ipA   = IPAddress.Parse(ip);
         IPEndPoint   point = new IPEndPoint(ipA, port);
         IAsyncResult ar    = clientSocket.BeginConnect(point, ConnectCallBack, clientSocket);
         TimeOutCheck(ar);
     }
 }
Exemple #2
0
 public void DisConnectAsyn(NormalCallBack disCallBack)
 {
     this.disConnectBack = disCallBack;
     if (clientSocket != null && clientSocket.Connected)
     {
         IAsyncResult ar = clientSocket.BeginDisconnect(false, DisConnectCallBack, clientSocket);
         if (!TimeOutCheck(ar))
         {
             disCallBack(false, SocketError.TimeOut, "发送时间超时");
         }
     }
     else
     {
         disCallBack(false, SocketError.DisConnectError, "Socket为空或者未连接");
     }
 }
Exemple #3
0
 public void SendAsyn(byte[] sendBytes, NormalCallBack sendCallBack)
 {
     this.sendBack = sendCallBack;
     if (clientSocket != null && clientSocket.Connected)
     {
         IAsyncResult ar = clientSocket.BeginSend(sendBytes, 0, sendBytes.Length, SocketFlags.None, SendCallBack, clientSocket);
         if (!TimeOutCheck(ar))
         {
             sendBack(false, SocketError.TimeOut, "发送时间超时");
         }
     }
     else
     {
         sendBack(false, SocketError.SendError, "Socket为空或者未连接");
     }
 }