private void NewMessageArried(string jsonStr) { FlowChatSendMessageData sendMessageData = JsonConvert.DeserializeObject <FlowChatSendMessageData>(jsonStr); if (flowChatMessageListBox1.CurrentSelectedItem.MessagerName == sendMessageData.SenderUserName) { ((FlowChatMessageContentSendCtrl)splitContainer1.Panel2.Controls[0]).AddMessageItem(sendMessageData.Content, false); } }
private void ParseMessageData(string jsonStr, NetworkStream stream) { FlowChatSendMessageData sendMessageData = JsonConvert.DeserializeObject <FlowChatSendMessageData>(jsonStr); var findedClient = serverApp.ConnectedClients.Where(o => o.isLogined && o.loginedUserData.UserName == sendMessageData.ReceiveUserName).FirstOrDefault(); if (findedClient != null) { findedClient.SendMessage(FlowChatConsts.NETWORK_RECV_DATA_USER_MESSAGE + "|" + jsonStr, stream); } else { SendMessage(FlowChatConsts.NETWORK_RECV_DATA_ERROR + "|Send Message Error, User can not be reached!", stream); } }
private void txtMessage_KeyDown(object sender, KeyEventArgs e) { switch (e.Modifiers) { case Keys.Enter: if (!string.IsNullOrEmpty(txtMessage.Text)) { txtMessage.Text = null; FlowChatSendMessageData messageData = new FlowChatSendMessageData(); messageData.ReceiveUserName = session.UserData.UserName; messageData.SenderUserName = messageItem.MessagerName; messageData.Content = txtMessage.Text; messageData.SendTime = DateTime.Now; string jsonstr = JsonConvert.SerializeObject(messageData); jsonstr = FlowChatConsts.NETWORK_SEND_DATA_MESSAGE + "|" + jsonstr; session.TcpClient.Client.Send(Encoding.UTF8.GetBytes(jsonstr)); AddMessageItem(txtMessage.Text, true); } break; } }