How to Use socket as a transfer time server in vb7 in asp.net

Source: Internet
Author: User

/*
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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.