Esempio n. 1
0
 public int CompareTo(object a)
 {
     if (a == null)
     {
         return(-1);
     }
     if (a != this)
     {
         TextMessage message = (TextMessage)a;
         if (this.m_Timestamp < message.m_Timestamp)
         {
             return(-1);
         }
         if (this.m_Timestamp > message.m_Timestamp)
         {
             return(1);
         }
     }
     return(0);
 }
Esempio n. 2
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            var username = tbUserName.Text.Trim();
            var msg      = tbSendMsg.Text.Trim();

            if (string.IsNullOrEmpty(username))
            {
                MessageBox.Show("用户名必填");
                return;
            }
            if (string.IsNullOrEmpty(msg))
            {
                MessageBox.Show("发生内容不能为空");
            }
            var model = new TextMessage
            {
                Content = msg
            };
            var cur = cbListUser.SelectedItem as BaseInfo;

            if (cur == null)
            {
                MessageBox.Show("请选择用户");
                return;
            }
            ShowMsg($"{_userName}:{msg}");
            _client.Send(new MessageCommand <TextMessage>
            {
                Content     = model,
                UserId      = _userId,
                UserName    = _userName,
                FromPrivate = _clientEndPoint,
                Target      = _currentConnectEndPoint
            });
            tbSendMsg.Clear();
        }
Esempio n. 3
0
 /*private void receiveVideo()
 {
     try
     {
         NetworkStream videoStream = videoSocket.GetStream();
         while(true)
         {
             if (videoStream.DataAvailable)
             {
                 ImageMessage msg = ImageMessage.recvMe(videoStream);
                 updatePictureBox(msg);
             }
         }
     }
     catch
     {
         return;
     }
 }*/
 private void updateLog(TextMessage m)
 {
     if(this.messageText.InvokeRequired)
     {
         this.Invoke(new updateLogDelegate(this.updateLog), new object[] { m });
     }
     else
     {
         if (m.messageType == MessageType.TEXT)
         {
             messageLog.SelectionFont = new Font(messageLog.Font, FontStyle.Regular);
             messageLog.SelectionColor = Color.Blue;
             messageLog.AppendText(m.username + " says: ");
             messageLog.SelectionColor = Color.Black;
             messageLog.AppendText(m.message + "\r\n\r\n");
         }
         else
         {
             messageLog.SelectionFont = new Font(messageLog.Font, FontStyle.Italic);
             messageLog.SelectionColor = Color.Red;
             messageLog.AppendText(m.username + " " + m.message+"\n");
         }
     }
 }
Esempio n. 4
0
 private void sendButton_Click(object sender, EventArgs e)
 {
     if (messageText.Text != "" && messageText.Text != null)
     {
         TextMessage t = new TextMessage();
         t.message = System.Text.RegularExpressions.Regex.Replace(messageText.Text, @"^\s*$\n", string.Empty, System.Text.RegularExpressions.RegexOptions.Multiline);
         t.username = user;
         t.messageType = MessageType.TEXT;
         msgToSend.Add(t);
     }
     messageText.Clear();
 }
Esempio n. 5
0
 private void messageText_KeyPress(object sender, KeyPressEventArgs e)
 {
     if (e.KeyChar == (char)13)
     {
         String s = System.Text.RegularExpressions.Regex.Replace(messageText.Text, @"^\s*$\n", string.Empty, System.Text.RegularExpressions.RegexOptions.Multiline);
         if (s != "" && s != null)
         {
             TextMessage t = new TextMessage();
             t.message = s;
             t.username = user;
             t.messageType = MessageType.TEXT;
             msgToSend.Add(t);
         }
         messageText.Clear();
     }
 }
Esempio n. 6
0
 private void esciToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (isConnected == true)
     {
         closeConnection();
         TextMessage t = new TextMessage();
         t.username = user;
         t.message = "si e' disconnesso";
         t.messageType = MessageType.DISCONNECT;
         updateLog(t);
     }
     this.Close();
 }
Esempio n. 7
0
 private void connectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (isConnected == false)
     {
         if (first == true)
         {
             settings = new Settings(this, user, ipAddr.ToString(), passw, port.ToString());
             settings.ShowDialog();
             //utente preme annulla
             if (first == true)
                 return;
         }
         isConnected = true;
         InitializeConnection();
         messageText.Enabled = true;
         sendButton.Enabled = true;
         connectToolStripMenuItem.Text = "Disconnetti";
     }
     else
     {
         closeConnection();
         TextMessage t = new TextMessage();
         t.username = user;
         t.message = "si e' disconnesso";
         t.messageType = MessageType.DISCONNECT;
         updateLog(t);
     }
 }
Esempio n. 8
0
 private void closeConnection()
 {
     try
     {
         threadKill();
         TextMessage t = new TextMessage();
         t.username = user;
         t.message = "si e' disconnesso";
         t.messageType = MessageType.DISCONNECT;
         t.sendMe(clientSocket.GetStream());
         if (clientSocket != null)
             clientSocket.Close();
         if (clipSocket != null)
             clipSocket.Close();
         if (videoSocket != null)
             videoSocket.Close();
         isConnected = false;
         messageText.Enabled = false;
         sendButton.Enabled = false;
         connectToolStripMenuItem.Text = "Connetti";
     }
     catch(Exception)
     { }
 }