private static void AcceptCallback(IAsyncResult ar) { Console.WriteLine("AsynchronousServer.AcceptCallback.Started"); AsynchronousServer self = (AsynchronousServer)ar.AsyncState; if (!self.m_Stopped) { self.m_AcceptDone.Set(); Socket handler = self.m_Listener.EndAccept(ar); State state = new State(); state.m_Socket = handler; state.m_ReceiveCallback = self.m_AcceptCallback(state); if (state.m_ReceiveCallback == null) { state.m_Socket.Close(); state.m_ReceiveDone.Set(); } else { handler.BeginReceive(state.m_Buffer, 0, State.cBufferSize, 0, new AsyncCallback(ReceiveCallback), state); } } Console.WriteLine("AsynchronousServer.AcceptCallback.Stopped"); }
public Proxy(string addrFrom, int portFrom, string addrTo, int portTo = -1) { m_AddrFrom = addrFrom; m_PortFrom = portFrom; m_AddrTo = addrTo; m_PortTo = portTo; m_Server = new AsynchronousServer(); m_Client = new AsynchronousClient(); m_ServerThread = new Thread(RunServer); m_ClientThread = new Thread(RunClient); }