public void Broadcast(int msgID, byte[] data)
 {
     if (IsActive)
     {
         byte[]     sendData = dataPacker.Packer(msgID, data);
         IPEndPoint remoteEP = new IPEndPoint(IPAddress.Broadcast, Port);
         socket.BeginSend(sendData, sendData.Length, remoteEP, SendResult, socket);
         Debug.Log("广播消息ID:" + msgID + " 大小:" + sendData.Length + "字节");
     }
 }
 public void Send(int msgID, byte[] data)
 {
     if (socket.Client != null && socket.Connected)
     {
         byte[] sendData = dataPacker.Packer(msgID, data);
         socket.GetStream().BeginWrite(sendData, 0, sendData.Length, SendResult, socket);
         Debug.Log("发送消息ID:" + msgID + " 大小:" + sendData.Length + "字节");
     }
 }
Exemple #3
0
 public void Send(int msgID, byte[] bodyData)
 {
     if (IsActive)
     {
         byte[] sendData = dataPacker.Packer(msgID, bodyData);
         for (int i = 0; i < remoteClients.Count; i++)
         {
             System.Net.Sockets.TcpClient client = remoteClients[i];
             if (client.Connected)
             {
                 client.GetStream().BeginWrite(sendData, 0, sendData.Length, SendResult, client);
             }
         }
         Debug.Log("发送消息ID:" + msgID + " 大小:" + sendData.Length + "字节");
     }
 }