Exemplo n.º 1
0
        public void TestClientSocketDisconnect()
        {
            ClientSocket client = new ClientSocket();

            client.BeginConnect(address, port);

            client.Disconnect();
            Assert.IsFalse(client.Connected);
        }
Exemplo n.º 2
0
        public void TestClientSocketConnect()
        {
            ClientSocket client = new ClientSocket();
            IAsyncResult result = client.BeginConnect(address, port);

            result.AsyncWaitHandle.WaitOne();

            Assert.IsTrue(client.Connected);
        }
Exemplo n.º 3
0
 public void Connect(IPEndPoint ip)
 {
     try
     {
         ClientSocket.BeginConnect(ip, ClientConnected, ClientSocket);
     }
     catch (Exception e)
     {
         OnErrorHandled?.Invoke(e);
     }
 }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 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();
            }
        }
Exemplo n.º 6
0
 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;
 }