コード例 #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();
                }
            }
        }
コード例 #2
0
        internal void OnDisconnected(ClientRepresentation client)
        {
            Disconnected?.Invoke();

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