EndSendTo() public method

public EndSendTo ( IAsyncResult asyncResult ) : int
asyncResult IAsyncResult
return int
Esempio n. 1
0
        public int EndSend(IAsyncResult asyncResult)
        {
            MyAsyncResult receiveAsyncResult = asyncResult as MyAsyncResult;

            if (receiveAsyncResult == null)
            {
                throw new ArgumentException("Invalid Async Result", "asyncResult");
            }

            return(_socket.EndSendTo(receiveAsyncResult.AsyncResult));
        }
 internal void SendToCallback(IAsyncResult ares)
 {
     try {
         BytesTransferred = curSocket.EndSendTo(ares);
     } catch (SocketException ex) {
         SocketError = ex.SocketErrorCode;
     } catch (ObjectDisposedException) {
         SocketError = SocketError.OperationAborted;
     } finally {
         OnCompleted(this);
     }
 }
Esempio n. 3
0
        public int EndSend(IAsyncResult asyncResult)
        {
            ThrowIfDisposed();

            if (_active)
            {
                return(_clientSocket.EndSend(asyncResult));
            }
            else
            {
                return(_clientSocket.EndSendTo(asyncResult));
            }
        }
Esempio n. 4
0
	    public static async Task<bool> DiscoverAsync(object state = null)
	    {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
            IPEndPoint endpoint = new IPEndPoint(IPAddress.Broadcast, 1900);

            byte[] outBuf = Encoding.ASCII.GetBytes(BroadcastPacket);
            byte[] inBuf = new byte[4096];

	        int tries = MaxTries;
	        while (--tries > 0)
	        {
	            try
	            {
	                TaskFactory factory = new TaskFactory();
	                sock.ReceiveTimeout = DiscoverTimeout;
	                await factory.FromAsync(sock.BeginSendTo(outBuf, 0, outBuf.Length, 0, endpoint, null, null), end =>
	                {
	                    sock.EndSendTo(end);
	                }).ConfigureAwait(false);
	                var ar = sock.BeginReceive(inBuf, 0, inBuf.Length, 0, null, null);
	                if (ar == null) throw new Exception("ar is null");
                    int length = await factory.FromAsync(ar, end => sock.EndReceive(end)).ConfigureAwait(false);

                    string data = Encoding.ASCII.GetString(inBuf, 0, length).ToLowerInvariant();

                    var match = ResponseLocation.Match(data);
                    if (match.Success && match.Groups["location"].Success)
                    {
                        System.Diagnostics.Debug.WriteLine("Found UPnP device at " + match.Groups["location"]);
                        string controlUrl = GetServiceUrl(match.Groups["location"].Value);
                        if (!string.IsNullOrEmpty(controlUrl))
                        {
                            _controlUrl = controlUrl;
                            System.Diagnostics.Debug.WriteLine("Found control URL at " + _controlUrl);
                            return true;                            
                        }
                    }

                }
	            catch (Exception ex)
	            {
	                // ignore timeout exceptions
	                if (!(ex is SocketException && ((SocketException) ex).ErrorCode == 10060))
	                {
	                    System.Diagnostics.Debug.WriteLine(ex.ToString());
	                }
	            }
	        }
            return false;
	    }
Esempio n. 5
0
        public int EndSend(IAsyncResult asyncResult)
        {
            if (_cleanedUp)
            {
                throw new ObjectDisposedException(this.GetType().FullName);
            }

            if (_active)
            {
                return(_clientSocket.EndSend(asyncResult));
            }
            else
            {
                return(_clientSocket.EndSendTo(asyncResult));
            }
        }
Esempio n. 6
0
 int Utils.Wrappers.Interfaces.ISocket.EndSendTo(System.IAsyncResult asyncResult)
 {
     return(InternalSocket.EndSendTo(asyncResult));
 }
        /// <summary>
        /// Sends an <see cref="ISnmpMessage"/>.
        /// </summary>
        /// <param name="message">The <see cref="ISnmpMessage"/>.</param>
        /// <param name="manager">Manager</param>
        /// <param name="socket">The socket.</param>
        public static void SendAsync(this ISnmpMessage message, EndPoint manager, Socket socket)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }

            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }

            if (manager == null)
            {
                throw new ArgumentNullException("manager");
            }

            var code = message.TypeCode();
            if ((code != SnmpType.TrapV1Pdu && code != SnmpType.TrapV2Pdu) && code != SnmpType.ReportPdu)
            {
                throw new InvalidOperationException(string.Format(
                    CultureInfo.InvariantCulture,
                    "not a trap message: {0}",
                    code));
            }

            var bytes = message.ToBytes();
            socket.BeginSendTo(bytes, 0, bytes.Length, SocketFlags.None, manager, ar => socket.EndSendTo(ar), null);
        }