|
-
Oct 9th, 2012, 08:57 AM
#1
Thread Starter
Frenzied Member
[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:
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
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Oct 9th, 2012, 09:41 AM
#2
Thread Starter
Frenzied Member
Re: Socket Receive
Solved
Use another version of the Receive method.
vb.net Code:
Dim bytesRec As Integer = sock.ReceiveFrom(SNTPData, iep)
Rate People That Helped You
Mark Thread Resolved When Resolved
-
Oct 9th, 2012, 09:41 AM
#3
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.
My usual boring signature: Nothing
 
-
Oct 9th, 2012, 11:24 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|