Ejemplo n.º 1
0
 public void listenNewUser()
 {
     while (true)
     {
         TcpClient tcpClient = Listener.AcceptTcpClient();
         TcpMessage msg = getTcpMessage(tcpClient);
         if (msg.getType().Equals(TcpMessage.TypeMsg.Login))
         {
             UserChat userChat = new UserChat(new UserInfo(msg.getLogin(), tcpClient), chatForm, this);
             Thread backgroundThread = new Thread(new ThreadStart(userChat.listenNewMessage));
             backgroundThread.Start();
             updateUsersList(userChat);
         }
         else
         {
             chatForm.printError(msg);
         }
     }
 }
Ejemplo n.º 2
0
 public ChatForm(bool isServer = false, UserInfo userInfo=null)
 {
     InitializeComponent();
     this.isServer = isServer;
     if (isServer)
     {
         socketServer = new SocketServer(8080, this);
         socketServer.start();
         ChatRichTextForm.AppendText("Server start\n");
         userChat = new UserChat(new UserInfo("server"), this);
     }
     else
     {
         userChat = new UserChat(userInfo, this);
         userChat.sendMessageObject(new TcpMessage(TcpMessage.TypeMsg.Login, "", userInfo.getName()));
         //userChat.sendMessage(userInfo.getName());
         Thread backgroundThread = new Thread(new ThreadStart(userChat.listenNewMessage));
         backgroundThread.Start();
     }
 }
Ejemplo n.º 3
0
 private void updateUsersList(UserChat userChat)
 {
     mapUsers.Add(userChat.getUserInfo().getName(), userChat.getUserInfo().getTcpClient());
     chatForm.printMessageChat("User was connected with login: " + userChat.getUserInfo().getName());
     chatForm.addUserToList(userChat.getUserInfo().getName());
 }