Exemplo n.º 1
0
 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 + "字节");
     }
 }
Exemplo n.º 2
0
        public void SendMessage(byte[] messageToSend)
        {
            if (isSendingMessage)
            {
                messageSendQueue.Enqueue(messageToSend);
                return;
            }

            isSendingMessage = true;
            udpClient.BeginSend(messageToSend, messageToSend.Length, ipEndpoint, OnMessageSent, null);
        }
Exemplo n.º 3
0
 public void SendPacket(Packet packet, IPEndPoint ipEndPoint)
 {
     try
     {
         udpClient.BeginSend(packet.ToArray(), packet.GetLength(), ipEndPoint, null, null);
     }
     catch (Exception exception)
     {
         Logger.LogError(LoggerSection.Network, $"Error sending UDP data to {ipEndPoint}: {exception}");
     }
 }
Exemplo n.º 4
0
        private void sendText_Click(object sender, EventArgs e)
        {
            //送信するデータを作成する
            byte[] sendBytes =
                System.Text.Encoding.UTF8.GetBytes(messageText.Text);

            //UdpClientを作成する
            if (UdpClient == null)
            {
                UdpClient = new System.Net.Sockets.UdpClient();
            }

            //非同期的にデータを送信する
            UdpClient.BeginSend(sendBytes,
                                sendBytes.Length,
                                connectIPAddress,
                                int.Parse(comPort.Text),
                                SendCallback,
                                UdpClient);

            messageText.Text = "";
        }