public SocksReplyMessage Start(string strRemoteHost, int nRemotePort) { SocksReplyMessage reply = new SocksReplyMessage(); reply.AddressType = AddressType.IPV4; bool bAccept = Listener.EnableAccept(0); if (bAccept == false) { reply.SOCKSReply = SOCKSReply.GeneralServerFailure; return reply; } IPEndPoint BoundEp = Listener.ListeningSocket.LocalEndPoint as IPEndPoint; bool bConnected = RemoteClient.Connect(strRemoteHost, nRemotePort, false); if (bConnected == false) { reply.SOCKSReply = SOCKSReply.ConnectionRefused; Listener.Close(); Listener = null; return reply; } reply.SOCKSReply = SOCKSReply.Succeeded; reply.BindAddress = BoundEp.Address; reply.BindPort = (ushort)BoundEp.Port; reply.AddressType = AddressType.IPV4; return reply; }
public ListenPortToRemoteEndpointForwardService(SOCKServer parent) { Parent = parent; RemoteClient = new SocketClient(); Listener = new SocketListener(); Listener.OnNewConnection += new SocketListener.DelegateNewConnectedSocket(Listener_OnNewConnection); RemoteClient.ReceiveHandlerBytes += new SocketClient.SocketReceiveHandler(RemoteClient_ReceiveHandlerBytes); RemoteClient.DisconnectHandler += new SocketClient.SocketEventHandler(RemoteClient_DisconnectHandler); }
static void Main(string[] args) { var listener = SocketListener.Create(1234, (message, session) => { if (message == ClientRequestString) { session.Write(ServerResponseString); } }); listener.Start(); var t = new Timer(s => { ConnectAsTcpClient(); }, null, 2000, 2000); Console.WriteLine("Keyboard waiting for newline"); Console.ReadLine(); listener.Stop(); }
void IncomingClient_DisconnectHandler(object sender, EventArgs e) { Parent.RemoveService(this); if (RemoteClient != null) { RemoteClient.Disconnect(); RemoteClient = null; } if (Listener != null) { Listener.Close(); Listener = null; } }
private static void StartListener() { SocketListener socketListener = new SocketListener(); //AsyncSocketListener listener = new AsyncSocketListener(); }