예제 #1
0
 public void ReceiveMessage(Message M)
 {
     txtConversation.Text += M.From + ": " + M.Content + '\n';
     txtConversation.CaretIndex = txtConversation.Text.Length;
     txtConversation.ScrollToEnd();
     txtMessage.Focus();
 }
예제 #2
0
 private void SendMessage()
 {
     Message M = new Message(client.LocalClientInfo.Name, Name, txtMessage.Text);
     client.SendMessageUDP(M, RemoteEP);
     txtConversation.Text += client.LocalClientInfo.Name + ": " + txtMessage.Text + '\n';
     txtMessage.Text = string.Empty;
     txtConversation.CaretIndex = txtConversation.Text.Length;
     txtConversation.ScrollToEnd();
     txtMessage.Focus();
 }
예제 #3
0
        /// <summary>
        /// Ask the server for updated users list
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.serverAddress), Properties.Settings.Default.port);

            Client.Start(endPoint);

            Shared.Message m = new Shared.Message();
            m.sender  = IPAddress.Parse(Properties.Settings.Default.ipv6);
            m.token   = Properties.Settings.Default.token;
            m.command = Command.Users;

            Client.Send(m);

            Client.Receive();
        }
예제 #4
0
        private void sendBtn_Click(object sender, RoutedEventArgs e)
        {
            if (messageTxt.Text != "" && messageTxt.Text != " ")
            {
                AddMessage(messageTxt.Text, Message.MessageOwner.YOU);

                IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse(Properties.Settings.Default.serverAddress), Properties.Settings.Default.port);
                Client.Start(endPoint);

                var m = new Shared.Message();
                m.command = Command.Message;
                m.sender  = IPAddress.Parse(Properties.Settings.Default.ipv6);
                m.content = messageTxt.Text;
                m.token   = Properties.Settings.Default.token;
                Client.Send(m);

                messageTxt.Text = "";
                Client.Receive();
            }
        }
예제 #5
0
        // Try to send a message to the Server
        public bool Send(Message Msg)
        {
            try
            {
                lock (Inner) // Thread safe
                    Msg.Serialise(Out);
            }
            catch
            {
                return false;
            }

            return true;
        }
 public void QueueMessage(Message message)
 {
     lock (_messages)
         _messages.Add(message);
 }
예제 #7
0
 // Send a message to a single client
 public void Send(Message m)
 {
     try
     {
         lock (Connection) // Thread safe
         {
             if (Connected)
                 m.Serialise(Out); // Serialise the message out
         }
     }
     catch
     {
         // If the send failed, treat it as a disconnect
         Disconnect(this, new DisconnectMessage(DisconnectType.Unexpected));
     }
 }
예제 #8
0
 public Message Create(Message msg)
 {
     msg.ID += 1;
     return msg;
 }
        private async Task sendConfirmationMessage()
        {
            try
            {
                string dataBuffer = "{\"lightState\": \"On\"}";
                Message eventMessage = new Message(Encoding.UTF8.GetBytes(dataBuffer));
                eventMessage.To = Config.Default.PartnerDevice;

                await deviceClient.SendEventAsync(eventMessage);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
예제 #10
0
파일: Client.cs 프로젝트: yaozd/P2Pchat
 public MessageReceivedEventArgs(ClientInfo _clientInfo, Message _message, IPEndPoint _establishedEP)
 {
     clientInfo = _clientInfo;
     message = _message;
     EstablishedEP = _establishedEP;
 }
 private async Task sendToTree(EmotionResult emotion)
 {
     var emotionJson = Newtonsoft.Json.JsonConvert.SerializeObject(emotion);
     Message m = new Message(Encoding.UTF8.GetBytes(emotionJson));
     m.To = Config.Default.PartnerDevice;
     Log("Sending to tree");
     await deviceClient.SendEventAsync(m);
     Log("Message sent");
 }