Exemple #1
0
        private void sendMessageButton_Click(object sender, EventArgs e)
        {
            newMessage = newMessageBox.Text;
            ObjectCollection.Message message = new ObjectCollection.Message()
            {
                Content = newMessage, Sender = me.Name
            };
            string json = JsonConvert.SerializeObject(message, Formatting.None);

            writer.WriteLine(json);
            writer.Flush();
            newMessageBox.Text = "";
        }
Exemple #2
0
 void UpdateUsersAndMessage()
 {
     while (client.Connected)
     {
         string resFromServ = reader.ReadLine();
         if (resFromServ != null)
         {
             if (resFromServ.Contains("Type\":\"users"))
             {
                 UsersCollection resUsers = JsonConvert.DeserializeObject <UsersCollection>(resFromServ);
                 dataGridView1.Invoke(new Action(() => { dataGridView1.DataSource = resUsers.Data; }));
             }
             else if (resFromServ.Contains("Type\":\"message"))
             {
                 ObjectCollection.Message resMessage = JsonConvert.DeserializeObject <ObjectCollection.Message>(resFromServ);
                 messageList.Text += resMessage.Content;
             }
         }
     }
 }