[RESOLVED] Socket Receive
Hi everyone
I have a little problem with a socket that i'm using to get the current date and time for an serve, i can send the request, but i don't receive anything.
The current code:
vb.net Code:
Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim ip As Net.IPHostEntry = Net.Dns.GetHostEntry("time-a.nist.gov")
Dim iep As New Net.IPEndPoint(ip.AddressList(0), 123)
sock.Connect(iep)
If sock.IsBound Then Debug.WriteLine("Connected...")
sock.SendTimeout = 3000
sock.ReceiveTimeout = 15000
Dim bytesSent As Integer = sock.Send(SNTPData)
Dim bytesRec As Integer = sock.Receive(SNTPData)
The SNTPData has the correct size and the correct format.
The timeout and the error:
Quote:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
What i'm missing here?
THanks
Re: [RESOLVED] Socket Receive
So, you get as far as send, but then the error occurs? Does it take you to the Send line such that the Receive line is never reached?
Frankly, I don't think the Receive line is all that good. If Send doesn't block, the Receive line will be executed pretty much immediately, before even a fast reply could arrive well. The socket should raise an event that you can handle, though to be fair, I have only worked with UDP lately, which isn't quite the same. In any case, the error doesn't sound consistent with this issue anyways. You are getting a timeout, which I would not expect to happen with the Receive call.
Re: [RESOLVED] Socket Receive
He could have simply set ReceiveTimeOut to 0 which would block until the socket actually received data. His code is throwing that exception because that's that the time out is supposed to do.