slt a tt
Je voudrais me connecter a un serveur ntp pour qu'il me transmet l'heure mais je ne connais pas vraiment cette class
je bug sur la connexion il me dit que le serveur a rejeté ma connexion
Pour le protocol j'ai trouvé
[ Lien ][code]
Imports
SystemImports
System.TextImports
System.IOImports
System.NetImports
System.Net.SocketsImports
Microsoft.VisualBasic
Public
Class Form1PrivateSharedFunction ConnectSocket(ByVal server AsString, ByVal port AsInteger) As SocketDim s As Socket = NothingDim hostEntry As IPHostEntry = Nothing' Get host related information.hostEntry = Dns.GetHostEntry(server)
' Loop through the AddressList to obtain the supported AddressFamily. This is to avoid' an exception that occurs when the host host IP Address is not compatible with the address family' (typical in the IPv6 case).Dim address As IPAddressForEach address In hostEntry.AddressListDim endPoint AsNew IPEndPoint(address, port)Dim tempSocket AsNew Socket(endPoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp)tempSocket.Connect(endPoint)
If tempSocket.Connected Thens = tempSocket
ExitForEndIfNext addressReturn sEndFunction
' This method requests the home page content for the specified server.PrivateSharedFunction SocketSendReceive(ByVal server AsString, ByVal port AsInteger) AsString'Set up variables to write to the server.Dim ascii As Encoding = Encoding.ASCIIDim request AsString = Date.UtcNow.ToStringDim bytesSent(8) As [Int64]Dim bytesReceived(8) As [Int64]bytesSent(0) =
CBool(1056964608)bytesSent(5) = 0
bytesSent(6) = 0
bytesSent(7) =
CBool(Date.UtcNow.ToString)' Create a socket connection with the specified server and port.Dim s As Socket = ConnectSocket(server, port)If s IsNothingThenReturn"Connection failed"EndIf' Send request to the server.s.Send(bytesSent, bytesSent.Length, 0)
' Receive the server home page content.Dim bytes As Int32' Read the first 256 bytes.
Dobytes = s.Receive(bytesReceived, bytesReceived.Length, 0)
LoopWhile bytes > 0Return bytesReceived(5).ToStringEndFunction
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickLabel1.Text = SocketSendReceive(
"time.windows.com", 123)EndSubEnd
Class[/code]