void acceptCompleted(Socket accepted) { // Send a ConnectionAccepted. try { ClientRepresentation client = new ClientRepresentation(this) { ClientSocket = accepted }; connectedClients.Add(client); client.MessageReceived += ProcessMessageBytes; client.SendBytes(SocketPipeHelper.BuildMessage(MessageType.ConnectionAccepted, null)); ClientConnected?.Invoke(this); client.AwaitBytes(); } finally { if (!isStopped) { serverAccept(); } } }
internal void OnDisconnected(ClientRepresentation client) { Disconnected?.Invoke(); if (AutoReconnect && reconnectTries < 10) { Thread.Sleep(5); reconnectTries++; Start(); } }
public void Start() { clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); int ipcPort = readPort(); try { clientSocket.Connect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), ipcPort)); client = new ClientRepresentation(this); client.ClientSocket = clientSocket; client.MessageReceived += ProcessMessageBytes; client.AwaitBytes(); } catch (Exception ex) { LoggerUtil.RecursivelyLogException(logger, ex); } }
internal void RemoveClient(ClientRepresentation client) { Console.WriteLine("Removing a client --------"); this.connectedClients.Remove(client); this.ClientDisconnected?.Invoke(this); }