Пример #1
0
 private static Exception ConnectNode(NodeInfo node, IProtocol p)
 {
     try
     {
         // 建立连接,注册重连函数
         p.Connect();
         byte[] data = LoginPass.GenHandShake(node.uid.ToString(), node.gameServer, node.subid, ++node.index);
         p.Send(DataPack.PackLength(data));
         data = p.Read();
         if (data.Length < 2)
         {
             DebugLogger.DebugNetworkError("Process Hand Shake Message Error: Data Length is Less Than 2");
             throw new NetworkingException((int)ErrorCode.DataError);
         }
         UInt32 code = ((UInt32)data[0] << 8) + (UInt32)data[1];
         if (code != (int)ErrorCode.Success)
         {
             DebugLogger.DebugNetworkError("Process Hand Shake Message Error: Connect Node Code is " + code);
             throw new NetworkingException((int)code);
         }
     }
     catch (Exception e)
     {
         return(e);
     }
     return(null);
 }
Пример #2
0
 public bool Connect(string port)
 {
     for (int i = 0; i < 3; i++)
     {
         if (_protocol.Connect(port))
         {
             return(true);
         }
     }
     return(false);
 }
Пример #3
0
        public void Connect_FailedThrice_ThreeTries()
        {
            IProtocol provider = Substitute.For <IProtocol>();

            provider.Connect(Arg.Any <string>()).ReturnsForAnyArgs(false);

//            provider.Connect(Arg.Is("COM1")).Returns(true);
//            provider.Connect(Arg.Is<string>(x=>x.StartsWith("COM"))).Returns(true);

            var sut = new Device(provider);

            sut.Connect(string.Empty);

            provider.Received(3).Connect(Arg.Any <string>());
        }
Пример #4
0
        internal static Exception Connect(NodeInfo node, IProtocol p)
        {
            p.Connect();
            // 连接后第一步,使用约定的加密密钥传输rid和uid来寻找对应的房间,之后采用加密通信传输数据
            // 暂时采用明文传输房间号 todo...
            byte[] data = System.Text.Encoding.Default.GetBytes(node.token);
            p.Send(DataPack.PackLength(data));
            // 等待服务端确认
            data = p.Read();
            string uid = System.Text.Encoding.Default.GetString(data);

            DebugLogger.Debug(string.Format("login to server {0}", uid));
            // 战斗不需要额外连接node
            return(null);
        }
Пример #5
0
        public void DllTest()
        {
            Assembly  a        = Assembly.LoadFrom(@"F:\Prog\gnutella2\bin\Debug\gnutella2.dll");
            Type      type     = a.GetType("ActionInnocence.P2PScan.ProtocolPlugin");
            IProtocol protocol = (IProtocol)Activator.CreateInstance(type, new string[] { @"F:\Prog\gnutella2\bin\Debug\", "192.168.1.38" });

            protocol.NewResult += new SearchResultHandler(protocol_NewResult);
            protocol.Connect();
            Thread.Sleep(1000 * 2);
            Keyword           w    = new Keyword("gnutella2", "madonna");
            KeywordCollection coll = new KeywordCollection();

            coll.Add(w);
            protocol.SearchKeyword(new SearchTransaction("1", coll, 1, null));
            System.Threading.Thread.Sleep(1000 * 30);
            protocol.Disconnect();
        }
Пример #6
0
        /// <summary>
        ///     Connect with remote host
        /// </summary>
        /// <param name="obj"></param>
        private void Connect(PasswordBox obj)
        {
            if (!IsConnected)
            {
                try
                {
                    if (ProtocolMode.Equals("SFTP"))
                    {
                        _protocol = new Sftp();
                    }
                    if (ProtocolMode.Equals("FTP"))
                    {
                        _protocol = new Ftp();
                    }
                    if (ProtocolMode.Equals("FTPS"))
                    {
                        _protocol = new Ftps();
                    }

                    IsConnected = _protocol.Connect(Server, Port, User, obj.Password);
                    RemotePath  = _protocol.WorkingDirectory();

                    if (IsConnected)
                    {
                        RemoteItems = new ObservableCollection <ProtocolItem>(_protocol.ListDirectory(RemotePath));
                    }
                }
                catch (Exception)
                {
                    // We need some data
                }
            }
            else
            {
                IsConnected = !_protocol.Disconnect();
                _protocol   = null;
                RemotePath  = null;
                RemoteItems.Clear();
                Tasks.Clear();
            }
        }
        /// <summary>
        /// Authentication for the repository.
        /// </summary>
        /// <param name="password"></param>
        public void Authentication(string password)
        {
            this.protocol =
                ProtocolFactory.Instance.GetProtocol(repository.CvsRoot.Protocol);

            this.protocol.Repository = this.Repository;
            this.protocol.Password   = password;

            protocol.Connect();
            this.inputStream  = protocol.InputStream;
            this.outputStream = protocol.OutputStream;


            // TODO: Move these into an abstract request class
            SubmitRequest(new ValidResponsesRequest());
            SubmitRequest(new ValidRequestsRequest());

            SubmitRequest(new UseUnchangedRequest());
            SubmitRequest(new RootRequest(repository.CvsRoot.CvsRepository));

            SubmitRequest(new GlobalOptionRequest(GlobalOptionRequest.Options.QUIET));
        }
        /// <summary>
        /// Authentication for the repository.
        /// </summary>
        /// <param name="password"></param>
        public void Authentication(string password) {
            this.protocol = 
                ProtocolFactory.Instance.GetProtocol(repository.CvsRoot.Protocol);

            this.protocol.Repository = this.Repository;
            this.protocol.Password = password;

            protocol.Connect();
            this.inputStream = protocol.InputStream;
            this.outputStream = protocol.OutputStream;


            // TODO: Move these into an abstract request class
            SubmitRequest(new ValidResponsesRequest());
            SubmitRequest(new ValidRequestsRequest());

            SubmitRequest(new UseUnchangedRequest());
            SubmitRequest(new RootRequest(repository.CvsRoot.CvsRepository));

            SubmitRequest(new GlobalOptionRequest(GlobalOptionRequest.Options.QUIET));
        }
Пример #9
0
 /// <summary>
 ///     连接设备
 /// </summary>
 /// <returns>设备是否连接成功</returns>
 public bool Connect()
 {
     return(ProtocolWrapper.Connect());
 }
Пример #10
0
 public RosSocket(IProtocol protocol)
 {
     Protocol            = protocol;
     Protocol.OnReceive += (sender, e) => Receive(sender, e);
     Protocol.Connect();
 }