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(); } }
/// <summary> /// Extends BeginSendToGroup so that when a state object is not needed, null does not need to be passed. /// <example> /// udpanysourcemulticastclient.BeginSendToGroup(buffer, offset, count, callback); /// </example> /// </summary> public static IAsyncResult BeginSendToGroup(this UdpAnySourceMulticastClient udpanysourcemulticastclient, Byte[] buffer, Int32 offset, Int32 count, AsyncCallback callback) { if (udpanysourcemulticastclient == null) { throw new ArgumentNullException("udpanysourcemulticastclient"); } return(udpanysourcemulticastclient.BeginSendToGroup(buffer, offset, count, callback, null)); }
/// <summary> /// Extends BeginSendToGroup so that buffer offset of 0 and call to Array.Length are not needed. /// <example> /// udpanysourcemulticastclient.BeginSendToGroup(buffer, callback, state); /// </example> /// </summary> public static IAsyncResult BeginSendToGroup(this UdpAnySourceMulticastClient udpanysourcemulticastclient, Byte[] buffer, AsyncCallback callback, Object state) { if (udpanysourcemulticastclient == null) { throw new ArgumentNullException("udpanysourcemulticastclient"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } return(udpanysourcemulticastclient.BeginSendToGroup(buffer, 0, buffer.Length, callback, state)); }
private void SendAsync(string message, Action success) { var buffer = Encoding.UTF8.GetBytes(message); socket.BeginSendToGroup(buffer, 0, buffer.Length, (ar) => { Deployment.Current.Dispatcher.BeginInvoke(() => { if (ar.IsCompleted) { success(); } } ); }, null); }
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); } }
void GroupJoined(IAsyncResult result) { MulticastData = Encoding.UTF8.GetBytes(MulticastMessage); keepsearching = true; MulticastSocket.BeginSendToGroup(MulticastData, 0, MulticastData.Length, callback_send, null); while (keepsearching) { try { byte[] buffer = new byte[MulticastData.Length]; MulticastSocket.BeginReceiveFromGroup(buffer, 0, buffer.Length, DoneReceiveFromGroup, buffer); } catch (Exception ex) { Debug.WriteLine("Stopped Group read due to " + ex.Message); keepsearching = false; } } }
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"); } }