/*
Tofu is made of excellent products.
Http://www.asp888.net bean curd technology station
If reprinted, indicate the source
*/
Using Socket, you can write a program that sends time to the client. Now, he can only send
Fixed client transfer time. I plan to write a program that can send time to the browser in a few days.
Please pay attention to the updates of my site at any time...
Imports System
Imports System. Net
Imports System. Net. Sockets
Imports System. Text
Public Class DateTimeServer
Public Shared Sub temp ()
System. Console. WriteLine ("hello ")
Console. Writeline ("Hello ")
End Sub
Public Shared Sub Main ()
Dim now As Date
Dim strDateLine As String
Dim ASCII As Encoding = Encoding. ASCII
Dim tcpl As New TCPListener (13) listen on port 13
Tcpl. Start ()
Console. WriteLine ("Waiting for clients to connect ")
Console. WriteLine ("Press Ctrl + c to Quit ...")
While (True)
Accept will block until someone connects
Dim s As Socket = tcpl. Accept ()
Get the current date and time then concatenate it
Into a string
Now = DateTime. Now
StrDateLine = now. tow.datestring () + "" + now. ToLongTimeString ()
Convert the string to a Byte Array and send it
Dim byteDateLine () As Byte = ASCII. GetBytes (strDateLine. ToCharArray ())
S. Send (byteDateLine, byteDateLine. Length, 0)
Console. WriteLine ("Sent" + strDateLine)
End While
End Sub
End Class