コード例 #1
0
        public void SendBytes(string value, Action <ClientSocket> errorHandle = null)
        {
            NetBufferWriter writer = new NetBufferWriter(value);

            byte[] sendData = writer.GetByte();
            try
            {
                socket.BeginSend(sendData, 0, sendData.Length, SocketFlags.None, SendCallBack, value);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                //断开连接
                Disconnect(errorHandle);
            }
        }
コード例 #2
0
 public void SendMsg(string msg)
 {
     if (clientSocket.Connected)
     {
         try
         {
             if (socketHandle == null)
             {
                 socketHandle     = new SocketHandle(clientSocket);
                 socketHandle.msg = msg;
             }
             NetBufferWriter netBufferWriter = new NetBufferWriter();
             byte[]          sendBuffer      = netBufferWriter.GetByte(msg);
             clientSocket.BeginSend(sendBuffer, 0, sendBuffer.Length, SocketFlags.None, SendCallBack, socketHandle);
         }
         catch (Exception e)
         {
             Debug.Log(e.Message);
         }
     }
 }