Beispiel #1
0
        public void Processing()
        {
            try
            {
                _stream = _client.GetStream();
                Parcel parcel = DecodeMessage();
                Username       = parcel.nickname;
                parcel.message = $"{parcel.nickname} enter to the chat!\n{parcel.message}";
                _server.Broadcast(parcel, Id);

                while (true)
                {
                    try
                    {
                        parcel   = DecodeMessage();
                        Username = parcel.nickname;
                        _server.Broadcast(parcel, Id);
                        Console.WriteLine($"{Username}: {parcel.message}");
                    }
                    catch
                    {
                        parcel.message = $"{Username} left the chat (((";
                        _server.Broadcast(parcel, Id);
                        Console.WriteLine(parcel.message);
                        throw;
                    }
                }
            }
            catch { }
            finally
            {
                Disconnect();
                _server.DisconnectClient(Id);
            }
        }
Beispiel #2
0
        public void Processing()
        {
            try
            {
                _stream = _client.GetStream();
                string message = DecodeMessage();

                _username = message;

                message += " joined to chat!";
                _server.BroadCast(message, Id);
                Console.WriteLine(message);


                while (true)
                {
                    try
                    {
                        message = DecodeMessage();
                        _server.BroadCast($"{_username}: {message}", Id);
                        Console.WriteLine($"{DateTime.Now.ToShortTimeString()}\t{_username} " +
                                          $"send message:\t{message}");
                    }
                    catch (Exception ex)
                    {
                        message = $"{_username} left the chat :( bye, bye ...";
                        _server.BroadCast(message, Id);
                        Console.WriteLine(message);
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"ERROR: {ex.Message}");
            }
            finally
            {
                Disconnect();
                _server.DisconnectClient(Id);
            }
        }
Beispiel #3
0
        public void Processing()
        {
            try
            {
                _stream = _client.GetStream();
                string message = DecodeMessage();

                _username = message;

                message += " enter to the chat!";
                _server.Broadcast(message, Id);
                Console.WriteLine(message);

                while (true)
                {
                    try
                    {
                        message = DecodeMessage();
                        _server.Broadcast($"{_username}: {message}", Id);
                        Console.WriteLine(message);
                    }
                    catch (Exception ex)
                    {
                        message = $"{_username} left the chat (((";
                        _server.Broadcast(message, Id);
                        Console.WriteLine(message);
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                //Console.WriteLine($"ERROR: {ex.Message}");
            }
            finally
            {
                Disconnect();
                _server.DisconnectClient(Id);
            }
        }