示例#1
0
        private void OnBeginAcceptSocket(IAsyncResult async)
        {
            TcpListener listener = async.AsyncState as TcpListener;

            try
            {
                Socket client = listener.EndAcceptSocket(async);
                this.WriteLineLog(string.Format("MarsNATRP_Server has received connecting request from {1} at {0}...", DateTime.Now, client.RemoteEndPoint));

                MarsNATRPServerConnection.DoRequest(this, client, this.Cliip, this.Cliport);
                if (this.IsStarting)
                {
                    listener.BeginAcceptSocket(this.OnBeginAcceptSocket, listener);
                }
            }
            catch (ObjectDisposedException) { }
            catch (Exception ex)
            {
                this.WriteLineLog(string.Format("An Exception ( {1} ) occurred at {0}", DateTime.Now, ex.Message));
            }
        }
        public static void DoRequest(MarsNATRPServerCore server, Socket client, string clientip, ushort clientport)
        {
            MarsNATRPServerConnection connection = new MarsNATRPServerConnection(server, client, clientip, clientport);

            ThreadPool.QueueUserWorkItem(new WaitCallback(connection.DoRequest));
        }