Example #1
0
        public void Procces()
        {
            try
            {
                userName = GetMessege();
                Console.WriteLine(userName);
                server.SendToAll(userName + " вошел в чат", this.id);

                string msg_info;
                string msg;
                while (true)
                {
                    try
                    {
                        msg_info = Response();
                        msg      = GetMessege();

                        Console.WriteLine(msg);

                        if (msg_info == "-1")
                        {
                            server.SendToAll(msg, this.id);
                            continue;
                        }
                        else if (msg_info == "-2")
                        {
                            foreach (byte[] clientdata in ServerObject.GetList())
                            {
                                stream.Write(clientdata);
                            }
                            continue;
                        }

                        ClientObject tmp = ServerObject.getClientFromNAME(msg_info);
                        if (tmp != null && tmp.active)
                        {
                            ServerObject.AddConectionWith(this, tmp);
                            server.SendTo(msg, this.id, msg_info);
                        }
                        else
                        {
                            Console.WriteLine("пользователя не существует");
                        }
                    }
                    catch
                    {
                        Console.WriteLine("-" + userName);
                        server.SendToAll(userName + " покинул чат", this.id);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                ServerObject.DelConnection(id);
                stream.Close();
                tcp.Close();
            }
        }