Maybe a stupid question, but I want to get the time from an ntp server on the internet. I have search this forum and dound that UDP is not supported, is that correct? at least that is what the Exception says when I try connecting through UDP. Then I thought ok, well I make a REST Wcf service that gives back the time in the form of a string. So all I have to do now is connect to this URL: http://localhost:10847/WcfNtpRestService/ and it will give me the current time. But then the next problem, every sample I tried to connect through sockets to that URL fails and I don’t know what I’m doing wrong. This is a peice of code that gives me errors:
// Get server's IP address.
IPHostEntry hostEntry = Dns.GetHostEntry(server);
// Create socket and connect to the server's IP address and port
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
socket.Connect(new IPEndPoint(new IPAddress(new byte[]{127, 0, 0, 1}), port));
return socket;
@ All: Thanks very much for your replies! The thing is, most of the suggestions you gave me I tried already, but with no success. But I will try them again to see what happens.
@ Architect: Your first suggestion was the HttWebResponse. To get HttpReponse to work I have to add a reference to the “System.Http” dll. As soon as I add this dll the code compiles succesfully, but as soon as I hit run visual studio pops up this message:
Error 1 An error has occurred. Please check your hardware
Whatever I try, the error won’t go away, I restarted my PC, I flashed the firmware again. But as soon as I remove the reference to “System.Http” dll everything works great again! Well except ofcourse the code that uses HttWebResponse.
@ Gus, sorry I did see that UDP was supported, but VS kept telling me trough exceptions it was not, now I see I had to use "SendTo"instead of “Send” and “ReceiveFrom”
I recommend that you simulate the NPT server on your PC. to test the communication with your FEZ Domino.
I mean make a little application on your PC that responds to the packets you are trying to send to the NTP server.
If your PC application receives the packet from FEZ Domino and FEZ Domino receives back the response. then this is a good start to change the IP to be the real NTP server.
Try this technique
socket.SendTo(bytesToSend, len, SocketFlags.None, ntpEndPoint);
while (socket.Poll(2000000, SelectMode.SelectRead))
{
if (socket.Available > 0)
{
byte[] inBuf = new byte[DnsSocket.Available];
EndPoint recEndPoint = null;
socket.ReceiveFrom(inBuf, ref recEndPoint);
if (!recEndPoint.Equals(ntpEndPoint))
continue;
}
}
}
I recommend a good network hub (not switch) and network monitor on your PC and sniff the traffic
And the UDP thing has been on a (no-forward-progress) to-do list for a while - the confirmation from your code of the send/recieve two step process was in line with what I thought too.
Hi Brett, thanks for your reply, but I’m pretty sure my network isn’t the problem, I have a $300 managed 1Gbit switch and I have the test service on my PC, so it is not gonna get any further the from the Domino to the switch and than to the wcf REST service on my PC. I’m really puzzled here on why I can’t get any response from that webservice. Does anyone have a complete working sample that I can try to connect to a URL so not persay through UDP, but lets say I want to connect to a local URL and get a response from it. http://localhost:10847/WcfNtpRestService/