Esempio n. 1
0
        /// <summary>
        /// Method starts communication between client and server
        /// </summary>
        /// <param name="clientInfo">Instance with all information about client</param>
        /// <returns>Running Task</returns>
        private Task CommunicateProcess(ClientInfo clientInfo)
        {
            return(Task.Run(() =>
            {
                while (true)
                {
                    string message = ReceiveMessage(clientInfo.Socket) + "\n";

                    storage.AddStoreMessage(clientInfo.Name, message);

                    lock (locker)
                    {
                        List <ClientInfo> list = socketHandler.HandleConnections(clients);

                        storage.AddLostConnectionMessages(list);

                        lostConnectionSender.BroadcastLostConnections(list);
                    }

                    BroadcastMessage(clientInfo.Name + ":" + message, clientInfo);

                    Console.Write(clientInfo.Name + ":" + message);
                }
            }));
        }