예제 #1
0
        private void HandleStartNewConnection(ProtocolSocket socket, int id, ushort targetPort, ushort internalPort)
        {
            Console.WriteLine($"HandleStartNewConnection #{id} target={targetPort} internal={internalPort}");
            var localSocket  = TryConnect(BoundInterface.ToString(), targetPort);
            var remoteSocket = TryConnect(RelayAddress, internalPort);
            var success      = localSocket != null && remoteSocket != null;

            if (IsConnected)
            {
                MainSocket.C2S_StartNewConnectionReply(id, internalPort, success);
            }
            var protoSocket = new ProtocolSocket(remoteSocket);

            protoSocket.C2S_StartRelay(id);
            var proxy = new ChannelProxy(localSocket);

            proxy.ChannelId = id;
            proxy.SetProxy(protoSocket);
        }