Exemplo n.º 1
0
        public static ISocket TcpListen(int port, int backlog = 10)
        {
            var listenSocket  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            var ip            = new IPAddress(new byte[] { 0, 0, 0, 0 });
            var localEndPoint = new IPEndPoint(ip, port);

            listenSocket.Bind(localEndPoint);
            listenSocket.Listen(backlog);
            return(AwesomeSocket.New(listenSocket));
        }
Exemplo n.º 2
0
        private static void TcpAcceptThread(ISocket listenSocket, Func <ISocket, Exception, Socket> callback)
        {
            Socket clientSocket = null;

            try
            {
                clientSocket = listenSocket.GetSocket().Accept();
            }
            catch (Exception ex)
            {
                callback(null, ex);
            }
            callback(AwesomeSocket.New(clientSocket), null);
        }