public void Send() { var msg = Encoding.ASCII.GetBytes(Message); try { var client = new UdpClient(); client.Client.Bind(new IPEndPoint(LocalAddress, 0)); client.BeginSend(msg, msg.Length, EndPoint, result => { try { client.EndSend(result); } catch (Exception ex) { Debug(ex); } finally { try { client.Close(); } catch (Exception) { } } }, null); } catch (Exception ex) { Error(ex); } ++SendCount; }
public void Send() { var msg = Encoding.ASCII.GetBytes(Message); try { var client = new UdpClient(); client.Client.Bind(new IPEndPoint(LocalAddress, 0)); client.Ttl = 10; client.Client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.MulticastTimeToLive, 10); client.BeginSend(msg, msg.Length, EndPoint, result => { try { client.EndSend(result); } catch (Exception ex) { _logger.Debug(ex); } finally { try { client.Close(); } catch (Exception) { } } }, null); } catch (Exception ex) { _logger.Error(ex); } ++SendCount; }
public void Send() { var msg = Encoding.ASCII.GetBytes(Message); foreach (var external in IP.ExternalIPAddresses) { try { var client = new UdpClient(new IPEndPoint(external, 0)); client.BeginSend(msg, msg.Length, EndPoint, result => { try { client.EndSend(result); } catch (Exception ex) { Debug(ex); } finally { try { client.Close(); } catch (Exception) { } } }, null); } catch (Exception ex) { Error(ex); } } ++SendCount; }
private void OnSent(IAsyncResult ar) { if (udp != null) { int bytesSent = udp.EndSend(ar); } }
//データを送信した時 private static void SendCallback(IAsyncResult ar) { System.Net.Sockets.UdpClient udp = (System.Net.Sockets.UdpClient)ar.AsyncState; //非同期送信を終了する try { udp.EndSend(ar); } catch (System.Net.Sockets.SocketException ex) { Debug.Log("送信エラー({0}/{1})" + " :" + ex.Message + " :" + ex.ErrorCode); } catch (ObjectDisposedException ex) { //すでに閉じている時は終了 Debug.Log("Socketは閉じられています。:" + ex.ToString()); } }
//データを送信した時 private static void SendCallback(IAsyncResult ar) { System.Net.Sockets.UdpClient udp = (System.Net.Sockets.UdpClient)ar.AsyncState; //非同期送信を終了する try { udp.EndSend(ar); } catch (System.Net.Sockets.SocketException ex) { Console.WriteLine("送信エラー({0}/{1})", ex.Message, ex.ErrorCode); } catch (ObjectDisposedException ex) { //すでに閉じている時は終了 Console.WriteLine("Socketは閉じられています。"); } }
private void SendCallback(IAsyncResult ar) { try { // Retrieve the socket from the state object. System.Net.Sockets.UdpClient client = (System.Net.Sockets.UdpClient)ar.AsyncState; // Complete sending the data to the remote device. int bytesSent = client.EndSend(ar); if (Debug) { Console.WriteLine("Sent {0} bytes to client.", bytesSent); } // Signal that all bytes have been sent. sendDone.Set(); } catch (Exception e) { Console.WriteLine(e.ToString()); } }