/// <summary> /// Sends to client. /// </summary> /// <param name="client">Client.</param> /// <param name="path">Path.</param> public void SendToClient(ConnectingClient client, string path) { try { client.Send(path); } catch (IOException ex) { OnClientDisconnected(new ClientDisconnectedEventArgs { Client = client }); } }
/// <summary> /// Sends to client. /// </summary> /// <param name="client">Client.</param> /// <param name="data">Data.</param> public void SendToClient(ConnectingClient client, byte[] data) { try { client.Send(data); } catch (IOException ex) { OnClientDisconnected(new ClientDisconnectedEventArgs { Client = client }); } }
private void listenForConnections() { while (true) { ConnectingClient client = new ConnectingClient(listener.AcceptTcpClient()); client.RecieveThread = new Thread(() => listenForMessages(client)); client.RecieveThread.Start(); ConnectedClients.Add(client); OnClientConnected(new ClientConnectedEventArgs { ConnectingClient = client }); } }
private void listenForMessages(ConnectingClient client) { try { while (true) { OnTextRecieved(new TextRecievedEventArgs { Client = client, Message = client.Input.ReadString() }); } } catch (IOException ex) { OnClientDisconnected(new ClientDisconnectedEventArgs { Client = client }); } }
/// <summary> /// Accepts the client. /// </summary> /// <param name="client">Client.</param> public void AcceptClient(ConnectingClient client) { AcceptedClients.Add(client); }