예제 #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);
            }
        }
예제 #2
0
파일: ClientEntity.cs 프로젝트: Den4983/hw
        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);
            }
        }