Esempio n. 1
0
        /// <summary>
        /// Starts the server.
        /// </summary>
        private void StartServer()
        {
            using (var server = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
            {
                server.Bind(new IPEndPoint(IPAddress.Any, Port));

                server.Listen(1);

                while (!_cancel)
                {
                    var connection = server.Accept();
                    if (connection.Poll(-1, SelectMode.SelectRead))
                    {
                        // Create buffer and receive raw bytes.
                        var bytes = new byte[connection.Available];

                        connection.Receive(bytes);

                        // Convert to string, will include HTTP headers.
                        var rawData = new string(Encoding.UTF8.GetChars(bytes));

                        EndPoint endPoint = InterpretRequest(rawData);

                        if (endPoint != null)
                        {
                            if (_enableLedStatus)
                            {
                                PingLed();
                            }

                            // dispatch the endpoint
                            var e = new EndPointEventArgs(endPoint, connection);

                            if (EndPointReceived != null)
                            {
                                ThreadUtil.SafeQueueWorkItem(() =>
                                {
                                    EndPointReceived(null, e);

                                    if (e.ManualSent)
                                    {
                                        // the client should close the socket
                                    }
                                    else
                                    {
                                        var response = e.ReturnString;

                                        SendResponse(response, connection);
                                    }
                                });
                            }
                        }
                        else
                        {
                            SendResponse(GetApiList(), connection);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
 public void DropMultiple(int Count)
 {
     ThreadUtil.SafeQueueWorkItem(new ThreadStart(() =>
     {
         for (int counter = 0; counter <= Count; counter++)
         {
             var c = Random.Next(65, 90);
             var x = Random.Next(1, 128 - _font.CharWidth((char)c));
             SingleDrop(x, (char)c);
         }
     }));
 }