예제 #1
0
        void UdpReceiveHandler(SharedArraySelectServer server, Socket sock)
        {
            EndPoint from = new IPEndPoint(IPAddress.Any, 0);

            int received = sock.ReceiveFrom(server.sharedArray, ref from);

            if (received < 0)
            {
                throw new Exception("ReceiveFrom failed");
            }
            String command = Encoding.ASCII.GetString(server.sharedArray, 0, received);

            if (command.Equals("stop"))
            {
                while (server.ListenSockets.Count > 0)
                {
                    var enumerator = server.ListenSockets.GetEnumerator();
                    Assert.AreEqual(true, enumerator.MoveNext());
                    Console.WriteLine("[SelectServer] Closing listen socket...");
                    server.DisposeAndRemoveListenSocket(enumerator.Current);
                }
                Console.WriteLine("[SelectServer] Closing UDP receive socket...");
                Console.Out.Flush();
                server.DisposeAndRemoveReceiveSocket(sock);
            }
        }
예제 #2
0
        void TcpReceiveHandler(SharedArraySelectServer server, Socket sock)
        {
            int received = sock.Receive(server.sharedArray);

            if (received <= 0)
            {
                server.DisposeAndRemoveReceiveSocket(sock);
            }
            else
            {
                Console.WriteLine("[SelectServer] Got {0} bytes", received);
            }
        }