Exemplo n.º 1
0
        /// <summary>
        /// Connect to a server!
        /// </summary>
        /// <param name="host">Address of the host. Can be a website or an ip address. IP addresses should be IPv4.</param>
        /// <param name="port">Port of the server on the host.</param>
        /// <returns></returns>
        public bool Connect(string host, int port)
        {
            Status = LoginClientStatus.LoginServer_Connecting;
            bool success = m_Network.Connect(host, port);

            if (success)
            {
                Status = LoginClientStatus.LoginServer_WaitingForLogin;

                byte[] clientVersion = Settings.UltimaOnline.ClientVersion;

                if (clientVersion.Length != 4)
                {
                    Tracer.Warn("Cannot send seed packet: Version array is incorrectly sized.");
                }
                else
                {
                    m_Network.Send(new SeedPacket(1, clientVersion));
                }
            }
            else
            {
                Status = LoginClientStatus.Error_CannotConnectToServer;
            }
            return(success);
        }
Exemplo n.º 2
0
        public HResult Open(string ip, int port)
        {
            try
            {
                ThrowIfError(CheckShutdown());

                _networkSender.Connect(ip, port);
                _networkSender.Start();
                SendDescribeRequest();

                return(HResult.S_OK);
            }
            catch (SocketException sex)
            {
                switch (sex.NativeErrorCode)
                {
                case 10060:
                    return(HResult.MF_E_NET_TIMEOUT);

                case 10061:
                    return(HResult.MF_E_NET_REDIRECT);

                default:
                    return(HResult.MF_E_NETWORK_RESOURCE_FAILURE);
                }
            }
            catch (Exception ex)
            {
                return(HResult.MF_E_NETWORK_RESOURCE_FAILURE);
            }
        }
Exemplo n.º 3
0
 public void Connect()
 {
     if (!IsConnect)
     {
         hostName = Properties.Settings.Default.HostIP;
         //string hostname = tbHostname.Text;
         //string port = tbPort.Text;
         //tbHostname.Enabled = false;
         //tbPort.Enabled = false;
         //tbSend.Enabled = true;
         //btnSend.Enabled = true;
         //btnConnect.Text = "Disconnect";
         string port;
         port = string.Format("{0:D3}", Properties.Settings.Default.PortServer);
         ClientOps ops = new ClientOps(this, hostName, port);
         m_client.Connect(ops);
         IsConnect = true;
     }
     else
     {
         //tbHostname.Enabled = true;
         //tbPort.Enabled = true;
         //btnConnect.Text = "Connect";
         //tbSend.Enabled = false;
         //btnSend.Enabled = false;
         if (m_client.IsConnectionAlive)
         {
             m_client.Disconnect();
             IsConnect = false;
         }
     }
 }
Exemplo n.º 4
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     if (btnConnect.Text.Equals("Connect"))
     {
         string hostname = tbHostname.Text;
         string port     = tbPort.Text;
         tbHostname.Enabled = false;
         tbPort.Enabled     = false;
         tbSend.Enabled     = true;
         btnSend.Enabled    = true;
         btnConnect.Text    = "Disconnect";
         ClientOps ops = new ClientOps(this, hostname, port);
         m_client.Connect(ops);
     }
     else
     {
         tbHostname.Enabled = true;
         tbPort.Enabled     = true;
         btnConnect.Text    = "Connect";
         tbSend.Enabled     = false;
         btnSend.Enabled    = false;
         if (m_client.IsConnectionAlive)
         {
             m_client.Disconnect();
         }
     }
 }
Exemplo n.º 5
0
 void Connect(string endpoint)
 {
     client = NetworkFactory.CreateNetworkClient <TcpNetworkClient> ();
     //client = NetworkFactory.CreateNetworkClient<RoomClientBridge> ();
     client.MessageHandler += (msg) => {
         RecieveMessage(msg);
     };
     client.Connect(endpoint);
 }
Exemplo n.º 6
0
        private void DoClientConnect()
        {
            _lastConnectTime = _stopwatch.ElapsedMilliseconds;

            var connectIp = SingletonManager.Get <ServerFileSystemConfigManager>().BootConfig.AllocationServer.ConnectIp;

            _logger.InfoFormat("Connection to Allocation Server {0}  HearBeatMessage HashCode {1}", connectIp, RpcMessageType.ServerHeartBeat.GetHashCode());
            _client.Connect(connectIp, _networkPortInfo);
        }
Exemplo n.º 7
0
        protected override void LoadContent()
        {
            _logger.Information("Content: Loading...");
            base.LoadContent();
            _worldRenderer.LoadContent(Content, GraphicsDevice);
            _logger.Information("Content: Loading...Done");

            _networkClient.Connect("localhost", 9050);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 网络集成测试
        /// </summary>
        public void NetworkIntergrateTest <T, V>(string connectStr)
            where T : INetworkServer, new()
            where V : INetworkClient, new()
        {
            //开启服务器
            INetworkServer server = NetworkFactory.CreateNetworkServer <T>();

            server.StartListen(connectStr);

            //测试用客户端进行连接
            INetworkClient client = null;

            ThreadPool.QueueUserWorkItem((o) => {
                Thread.Sleep(50); //假设50毫秒服务器可以开起来
                client = NetworkFactory.CreateNetworkClient <V>();
                client.Connect(connectStr);
            });

            //服务器获得新的session
            INetworkClientSession session = BlockWaitNewClient(server);

            Assert.IsNotNull(session);
            Assert.IsNotNull(client);
            Assert.IsTrue(client.Connected);

            //测试客户端往服务器发消息
            var testMsg = new GameMessage()
            {
                stateCode = 9999
            };

            client.Send(testMsg);
            var msg = BlockRead(session);

            Assert.AreEqual(msg.stateCode, 9999);

            //测试服务器往客户端发消息
            session.Send(new SyncMessage()
            {
                stateCode = 9993, timeleft = 3333
            });
            msg = BlockRead(client);
            Assert.IsTrue(msg is SyncMessage);
            Assert.AreEqual(msg.stateCode, 9993);
            Assert.AreEqual((msg as SyncMessage).timeleft, 3333);

            //关闭连接
            client.Close();
            Assert.IsFalse(client.Connected);
            session.Close();
            Assert.IsFalse(session.Connected);

            //关闭服务器
            server.Shutdown();
        }
Exemplo n.º 9
0
 // ============================================================================================================
 // Connection and Disconnect
 // ============================================================================================================
 public bool Connect(string host, int port, string account, SecureString password)
 {
     Disconnect();
     if (_network.Connect(host, port))
     {
         _userName = account;
         _password = password;
         _network.Send(new SeedPacket(0x1337BEEF, UltimaGameSettings.UltimaOnline.PatchVersion));
         Login(_userName, _password);
         return(true);
     }
     return(false);
 }
Exemplo n.º 10
0
        public LoginClient(
            string serverIp,
            NetworkPortInfo networkPortInfo,
            IClientRoom clientRoom)
        {
            this._clientRoom = clientRoom;

            //INetworkClientFactory clientFactory = new UNetNetworkClientFactory();
            //INetworkClientFactory clientFactory = new ENetNetworkClientFactory();
            INetworkClientFactory clientFactory = new VNetworkClientFactory();

            _networkClient = clientFactory.CreateNetworkClient(SharedConfig.IsLittleEndian, "BattleClient");

            _networkClient.ChannelConnected    += NetworkClientOnChannelConnected;
            _networkClient.ChannelDisconnected += NetworkClientOnChannelDisconnected;
            _networkClient.Connect(serverIp, networkPortInfo, SharedConfig.MutilThread);
            SingletonManager.Get <DurationHelp>().ServerInfo = string.Format("{0} tcp:{1} udp:{2}", serverIp, networkPortInfo.TcpPort, networkPortInfo.UdpPort);
        }
Exemplo n.º 11
0
 public void Connect()
 {
     client.Connect();
 }