Exemplo n.º 1
0
        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();
                }
            }
        }
Exemplo n.º 2
0
        internal void OnDisconnected(ClientRepresentation client)
        {
            Disconnected?.Invoke();

            if (AutoReconnect && reconnectTries < 10)
            {
                Thread.Sleep(5);
                reconnectTries++;
                Start();
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
 internal void RemoveClient(ClientRepresentation client)
 {
     Console.WriteLine("Removing a client --------");
     this.connectedClients.Remove(client);
     this.ClientDisconnected?.Invoke(this);
 }