Beispiel #1
0
        static void Main(string[] args)
        {
            var serverAddress = "192.168.0.196";
              var queueName = "message_data_cs";

              using (var conn = new ConnectionFactory().CreateConnection(serverAddress))
              {
            using (var ch = conn.CreateModel())
            {
              ch.QueueDeclare(queueName, true);
              var properties = ch.CreateBasicProperties();
              properties.SetPersistent(true);

              for (int i = 0; i < 10; i++)
              {
            var message = new Message()
            {
              From = "C# Sample",
              Body = String.Format("Message No. {0}", i)
            };

            Console.WriteLine("Sending: {0}", i);
            ch.BasicPublish("", queueName, properties, Message.Serialize(message));
              }
            }
              }
        }
Beispiel #2
0
 private void ListenSocket()
 {
     while (_socket.Connected)
     {
         Message recievedMessage = (Message)_bf.Deserialize(_networkStream);
         lstPanel.Items.Add(recievedMessage.ToString());
     }
 }
Beispiel #3
0
 private void ListenSocket()
 {
     while (true)
     {
         Message message = (Message)_bf.Deserialize(_networkStream);
         lstPanel.Items.Add(message);
     }
 }
 public static byte[] Serialize(Message message)
 {
     using (var ms = new MemoryStream())
       {
     Serializer.Serialize(ms, message);
     return ms.ToArray();
       }
 }
Beispiel #5
0
 public static byte[] Serialize(Message message)
 {
     using (var ms = new MemoryStream())
       {
     var bf = new BinaryFormatter();
     bf.Serialize(ms, message);
     return ms.ToArray();
       }
 }
Beispiel #6
0
        private void BtnSendMessage_Click(object sender, EventArgs e)
        {
            Message message = new Message
            {
                Content  = txtMessage.Text,
                SendedAt = DateTime.Now,
                Sender   = "Server Message:"
            };

            _bf.Serialize(_networkStream, message);
            _networkStream.Flush();
            lstPanel.Items.Add(message.ToString());
            txtMessage.Clear();
            txtMessage.Focus();
        }