public void TestClientSocketDisconnect() { ClientSocket client = new ClientSocket(); client.BeginConnect(address, port); client.Disconnect(); Assert.IsFalse(client.Connected); }
public void TestClientSocketConnect() { ClientSocket client = new ClientSocket(); IAsyncResult result = client.BeginConnect(address, port); result.AsyncWaitHandle.WaitOne(); Assert.IsTrue(client.Connected); }
public void Connect(IPEndPoint ip) { try { ClientSocket.BeginConnect(ip, ClientConnected, ClientSocket); } catch (Exception e) { OnErrorHandled?.Invoke(e); } }
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); } }
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(); } }
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; }