Esempio n. 1
0
        /// <summary>
        /// Accept a incoming TCP conneciton
        /// </summary>
        /// <param name="ar">async result</param>
        static public void OnAcceptTcpClientCallback(IAsyncResult ar)
        {
            MyCached myCached = (MyCached)ar.AsyncState;

            Trace.TraceInformation("OnAcceptTcpClientCallback");

            try
            {
                TcpClient client = myCached.listener.EndAcceptTcpClient(ar);
                Trace.TraceInformation("Accepting connection from : {0}", client.Client.RemoteEndPoint.ToString());

                TcpConnection connection = new TcpConnection(client);

                connection.OnPacketsReceived += myCached.OnPacketsReceived;

                lock (myCached.clientConnections)
                {
                    myCached.clientConnections.Add((IPEndPoint)client.Client.RemoteEndPoint, connection);
                }

                myCached.listener.BeginAcceptTcpClient(
                    new AsyncCallback(OnAcceptTcpClientCallback),
                    myCached);
            }
            catch (Exception e)
            {
                Trace.TraceInformation("OnAcceptTcpClientCallback: Caught exception {0}", e.ToString());
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            MyCached cached = new MyCached();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                cached.Stop();
            };

            Trace.TraceInformation("Starting mycached service...");
            cached.Run();
            Trace.TraceInformation("Exiting mycached service...");
        }