Exemple #1
0
        public void SendTo(byte[] messageData, UdpEndPoint endPoint)
        {
            if (messageData == null)
            {
                throw new ArgumentNullException("messageData");
            }
            if (endPoint == null)
            {
                throw new ArgumentNullException("endPoint");
            }

            ThrowIfDisposed();

            var signal = new System.Threading.ManualResetEvent(false);

            try
            {
                _UdpClient.BeginSendToGroup(messageData, 0, messageData.Length,
                                            (asyncResult) =>
                {
                    _UdpClient.EndSendToGroup(asyncResult);
                    signal.Set();
                }
                                            , null
                                            );
                signal.WaitOne();
            }
            finally
            {
                signal.Dispose();
            }
        }
Exemple #2
0
        private void Send(byte[] data)
        {
            // Attempt the send only if you have already joined the group.
            if (_joined)
            {
                _client.BeginSendToGroup(data, 0, data.Length,
                                         result =>
                {
                    _client.EndSendToGroup(result);

                    // Log what we just sent
                    //Log(message, true);
                }, null);
            }
            else
            {
                //Log("Message was not sent since you are not joined to the group", true);
            }
        }
        private void Send(string message)
        {
            // Attempt the send only if you have already joined the group.
            if (_joined)
            {
                byte[] data = Encoding.UTF8.GetBytes(message);
                _client.BeginSendToGroup(data, 0, data.Length,
                                         result =>
                {
                    _client.EndSendToGroup(result);

                    // Log what we just sent
                    Log(message);
                }, null);
            }
            else
            {
                MessageBox.Show("Cant receive - not connected to Multicast group");
            }
        }