示例#1
0
        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;
        }
示例#2
0
 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);
 }
示例#3
0
        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();
        }
示例#4
0
 void IncomingClient_DisconnectHandler(object sender, EventArgs e)
 {
     Parent.RemoveService(this);
     if (RemoteClient != null)
     {
         RemoteClient.Disconnect();
         RemoteClient = null;
     }
     if (Listener != null)
     {
         Listener.Close();
         Listener = null;
     }
 }
示例#5
0
 private static void StartListener()
 {
     SocketListener socketListener = new SocketListener();
     //AsyncSocketListener listener = new AsyncSocketListener();
 }