예제 #1
0
        void Sender()
        {
            while (!End)
            {
                try
                {
                    SuzukiMessage msg = SendQueue.Take();

                    Byte[] data = Encoding.ASCII.GetBytes(msg.Msg);

                    TcpClient client = new TcpClient(msg.Address, msg.Port);

                    NetworkStream stream = client.GetStream();
                    stream.Write(data, 0, data.Length);

                    stream.Close();
                    client.Close();
                }
                catch (SocketException e)
                {
                    LogMessage(this, e.ToString());
                }
                catch (InvalidOperationException)
                {
                    // SendQueue has ended.
                }
            }
        }
예제 #2
0
    private async void RunSend()
    {
        Debug.Log("WebSocket Message Sender looping.");
        ArraySegment <byte> msg;

        while (!SendQueue.IsCompleted)
        {
            msg = SendQueue.Take();
            await ws.SendAsync(msg, WebSocketMessageType.Binary, true, CancellationToken.None);
        }
    }
예제 #3
0
 public void Start()
 {
     try
     {
         while (true)
         {
             using var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
             var message = _queue.Take();
             Logger.Log($"Took {message} out of queue");
             SendMessage(message, socket);
         }
     }
     catch (ObjectDisposedException) {}
     catch (OperationCanceledException) {}
     catch (ThreadInterruptedException) {}
     catch (Exception e) { Logger.LogException(e); }
 }