コード例 #1
0
ファイル: NetSocket.cs プロジェクト: unityHUI/UnityFrame
 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);
     }
 }
コード例 #2
0
ファイル: NetSocket.cs プロジェクト: unityHUI/UnityFrame
 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为空或者未连接");
     }
 }
コード例 #3
0
ファイル: NetSocket.cs プロジェクト: unityHUI/UnityFrame
 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为空或者未连接");
     }
 }