コード例 #1
0
ファイル: HyperSocket.cs プロジェクト: suxf/EasySharpFrame
        /// <summary>
        /// 验证服务器数据
        /// </summary>
        internal void VerifyServerData(byte[] data)
        {
            var str = Encoding.UTF8.GetString(data);

            if (str.ElementAt(0) == '0')
            {
                IsValid = true;
                IsAlive = true;
                timeFlow.StartTimeFlowES();
                SendTcp(ConnectedClientBytes);
            }
            else if (str.ElementAt(0) == '1')
            {
                IsValid = true;
                IsAlive = true;
                var publicKey = str.Substring(2);
                config.UseSSL  = true;
                config.SSLMode = int.Parse(str.ElementAt(1).ToString());
                ssl            = new SSL(SSL.SSLMode.Both, publicKey);
                tcpClient.Send(SessionId, ssl.RSAEncrypt(ssl.GetAESKey().AsBytes()));
            }
            else
            {
                Close();
            }
        }
コード例 #2
0
 internal RemoteHyperSocket(ushort sessionId, HyperSocket hyperSocket, HyperSocketConfig config)
 {
     if (config.UseSSL)
     {
         ssl = new SSL(SSL.SSLMode.AES);
     }
     hyperSocketRef = new WeakReference <HyperSocket>(hyperSocket);
     SessionId      = sessionId;
     kcpHelper      = new KcpHelper(sessionId, (int)config.UdpReceiveSize, config.KcpWinSize, config.kcpMode, this);
 }
コード例 #3
0
ファイル: HyperSocket.cs プロジェクト: suxf/EasySharpFrame
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="IsServerMode"></param>
        /// <param name="ip"></param>
        /// <param name="tcpPort"></param>
        /// <param name="udpPort"></param>
        /// <param name="connectMaxNum"></param>
        /// <param name="config"></param>
        private HyperSocket(bool IsServerMode, string ip, uint tcpPort, uint udpPort, uint connectMaxNum, HyperSocketConfig config)
        {
            this.IsServerMode = IsServerMode;

            this.ip = ip;
            TcpPort = tcpPort;
            UdpPort = udpPort;
            if (connectMaxNum < ushort.MaxValue - 1)
            {
                connectMaxNum += 1;
            }
            this.connectMaxNum = connectMaxNum;
            this.config        = config;

            if (this.IsServerMode)
            {
                remoteSockets = new RemoteHyperSocket[connectMaxNum];
                ssl           = new SSL(SSL.SSLMode.RSA);
            }

            timeFlow = BaseTimeFlow.CreateTimeFlow(this);
        }