Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket.SendTo/ReceiveFrom crash when send/receive timeouts are set #1

Open
misenhower opened this issue May 27, 2015 · 0 comments
Open

Comments

@misenhower
Copy link

I noticed a crash when using SendTo and ReceiveFrom with sockets that have SendTimeout or ReceiveTimeout values set. As an example, the following code throws an ArgumentOutOfRange exception:

// Wait for DHCP
while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
    Thread.Sleep(50);

// Set up a sample IP endpoint
IPAddress ip = Dns.GetHostEntry("time-a.nist.gov").AddressList[0];
EndPoint remoteEndPoint = new IPEndPoint(ip, 123);

// Set up a send/receive buffer with sample data
byte[] buffer = new byte[48];
buffer[0] = 0x1B;

using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
    socket.SendTimeout = 1000;
    socket.ReceiveTimeout = 1000;

    socket.SendTo(buffer, remoteEndPoint);
    socket.ReceiveFrom(buffer, ref remoteEndPoint);
}

If you comment out the SendTimeout line, the call to SendTo completes successfully. Similarly, commenting out the ReceiveTimeout line makes the ReceiveFrom call complete successfully.

This issue does not appear to be present when using the Send/Receive methods.

Please let me know if you need any more information. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant