您当时的方位:主页 > 言语编程 > ASP.NET

asp.net中的vb7中怎么运用socket作一个传送时刻的server

2014-10-28  
/*
豆腐制造,都是精品
http://www.asp888.net 豆腐技能站
如转载 请注明出处
*/

运用Socket 能够编写一个 向 客户端传送 时刻的 一个程序,现在他还只能向
固定的客户端 传送时刻,我计划过几天 写一个 能够向 浏览器传送 时刻的一个程序
请咱们随时留意我的站点的更新状况。。。
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/n")
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.ToShortDateString() + " " + 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