Пример #1
0
        private void button_Login_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox_Name.Text))
            {
                MessageBox.Show("Input your name!");
                return;
            }

            manager = new MessageSocketManager(textBox_Name.Text, this);
            manager.addMessageHandler(ServerID, ClientMessageControler);
            manager.Connect(new IPHostEndPoint(Server_IP, Server_Port), null);
        }
Пример #2
0
        /// <summary>
        /// \brief Handle all incoming messages for this client.
        ///
        /// This is done using the static MessageHandler.HandleIncomingJsonMessage() method.
        /// When the clients' connection closes, the client will be remove from the connected clients list in the MessageSocketManager.
        /// This method is called in the constructor method of ClientMessageSocket.
        /// </summary>
        private void HandleIncomingMessagesFromClient()
        {
            while (innerClient.Connected && IsConnected())
            {
                var stream = innerClient.GetStream();
                if (stream.DataAvailable && !isCalling)
                {
                    MessageHandler.HandleIncomingJsonMessage(this, GetStringFromNetworkStream(stream));
                }
            }

            // When the connection is closed, remove this client from  the list in MessageSocketManager.
            MessageSocketManager.RemoveClientFromConnectedSockets(this);
        }
Пример #3
0
        /// <summary>
        /// Log the user and client out.
        /// The ClientMessageSocket client is removed from the connectedSockets list in the MessageSocketManager and the connection is removed from the database.
        ///
        /// The LogOut message should containt the following values:
        /// - ClientID: the ID of the table
        /// - ID: the ID of the user
        /// An MissingFieldException  will be thrown if the message does not contain these values.
        /// </summary>
        /// <param name="jsonObject">The LogOut message</param>
        private static void LogOut(dynamic jsonObject)
        {
            // Search for the client in the connectedSockets list of the MessageSocketManager class.
            var client = MessageSocketManager.GetClientMessageSocketById(jsonObject.CLIENTID);

            // Remove the client from the connectedSockets list if it is not null.
            if (client != null)
            {
                MessageSocketManager.RemoveClientFromConnectedSockets(client);
            }
            // Remove the connection from the database.
            var dbManager = new DatabaseManager();

            dbManager.DisconnectGuestFromTable(jsonObject.ID, jsonObject.ClientID);
            dbManager.Close();
        }
Пример #4
0
        /// <summary>
        /// \brief Create a new CallConnection between the specified client and a random client.
        ///
        /// The random client is selected using the MessageSocketManager.GetRandomPendingConnection() method.
        /// When a CallConnection is created, the callConnections list in the MessageSocketManager class will be updated accordingly.
        /// If no random client is found, the client will be stored in the pendingRandomCallConnections list of the MessageSocketManager class.
        /// This will be done using the MessageSocketManager.AddPendingRandomCallClient();
        /// </summary>
        /// <param name="message">The message.</param>
        /// <param name="client">The ClientMessageSocket client to connect the CallConnection to.</param>
        private static void GetRandomTable(dynamic message, ClientMessageSocket client)
        {
            var clientId    = message.ClientID;
            var randomTable = MessageSocketManager.GetRandomPendingConnection();

            // If another random request is lined up, use that table.
            // Otherwise, place this table in the wait list.
            if (randomTable != null)
            {
                var callConnection = new CallConnection(client, randomTable);
                // Update the callConnections list in the MessageSocketManager class accordingly.
                MessageSocketManager.AddCallConnection(callConnection);
            }
            else
            {
                // Add the client to the pendingRandomCallConnections list of the MessageSocketManager class.
                MessageSocketManager.AddPendingRandomCallClient(client);
            }
        }
Пример #5
0
        public void GivenANewClientIsConnected()
        {
            var mainwindowSub = Substitute.ForPartsOf <MainWindow>();

            mainwindowSub.When <MainWindow>(x => x.SetNumberOfConnectedCalls(Arg.Any <int>())).DoNotCallBase();
            mainwindowSub.When <MainWindow>(x => x.SetNumberOfConnectedClients(Arg.Any <int>())).DoNotCallBase();
            mainwindowSub.When <MainWindow>(x => x.SetNumberOfPendingCalls(Arg.Any <int>())).DoNotCallBase();

            messageSocketManager = new MessageSocketManager(Substitute.For <MainWindow>());

            tcpClient = new TcpClient();
            tcpClient.Connect("localhost", 30000);

            dynamic connectMessage = new ExpandoObject();

            connectMessage.ClientID = "1";
            connectMessage.ID       = "1";

            WriteToTcpClient(JsonConvert.SerializeObject(connectMessage));
        }
 public ChatMessageServerManager()
 {
     _OnLineTable        = new ConcurrentDictionary <string, MessageControler>();
     _ChatMessageManager = new MessageSocketManager("MessageServer", this);
 }