コード例 #1
0
        public void TestClientSocketDisconnect()
        {
            ClientSocket client = new ClientSocket();

            client.BeginConnect(address, port);

            client.Disconnect();
            Assert.IsFalse(client.Connected);
        }
コード例 #2
0
        public void TestClientSocketConnect()
        {
            ClientSocket client = new ClientSocket();
            IAsyncResult result = client.BeginConnect(address, port);

            result.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(client.Connected);
        }
コード例 #3
0
 public void Connect(IPEndPoint ip)
 {
     try
     {
         ClientSocket.BeginConnect(ip, ClientConnected, ClientSocket);
     }
     catch (Exception e)
     {
         OnErrorHandled?.Invoke(e);
     }
 }
コード例 #4
0
ファイル: ClientTCP.cs プロジェクト: uvbs/OpenAo
        private void StartClient()
        {
            try
            {
                var ipHostInfo = Dns.GetHostEntry(ServerAddress);
                var ipaddress  = ipHostInfo.AddressList[0];
                var RemoteEP   = new IPEndPoint(ipaddress, ServerPort);

                ClientSocket.BeginConnect(RemoteEP, new AsyncCallback(ConnectionCallBack), ClientSocket);

                ConnectDone.WaitOne();

                SendDone.WaitOne();

                Receive(ClientSocket);

                ReceiveDone.WaitOne();
            }
            catch (Exception ex)
            {
                ErrorLogger.LogException(ex);
            }
        }
コード例 #5
0
        public static void Connect(bool pendingPackets = false)
        {
            try
            {
                ClientSocket.BeginConnect("127.0.0.1", 6969, (result) =>
                {
                    if (result != null && ClientSocket.Connected)
                    {
                        ClientSocket.EndConnect(result);

                        App.Info("Connection to the server has been established!");

                        PacketProcessor.OnPacketProcessed = onPacketProcessed;

                        if (pendingPackets)
                        {
                            ProcessPengingPackets();
                        }

                        AwaitPendingPackets.WaitOne();

                        beginReceive();

                        return;
                    }
                }, null);
            }
            catch
            {
                App.Warn("Failed to connect! retrying in 3 seconds...");

                Thread.Sleep(3000);

                Connect();
            }
        }
コード例 #6
0
ファイル: Client.cs プロジェクト: vadian/Novus
 private void ClientConnect()
 {
     ClientSocket.BeginConnect(new System.Net.IPEndPoint(IPAddress, Port), new AsyncCallback(ConnectCallback), null);
     Console.WriteLine(">>>Client connected to IP:" + IPAddress.ToString() + "   Port: " + Port + " <<<");
     Connected = true;
 }