EndSend() public method

public EndSend ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int
Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 private void OnSent(IAsyncResult ar)
 {
     if (udp != null)
     {
         int bytesSent = udp.EndSend(ar);
     }
 }
Ejemplo n.º 5
0
        //データを送信した時
        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());
            }
        }
Ejemplo n.º 6
0
        //データを送信した時
        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は閉じられています。");
            }
        }
Ejemplo n.º 7
0
        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());
            }
        }