当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > asp.net中的vb7中如何使用socket作一个传送时间的server

ASP.NET
一个多文档界面的应用程序
asp+ 制作图形
asp.net中的vb7中如何调用dll中的函数
asp.net中的vb7中如何使用socket作一个传送时间的server
asp+发送Email完全手册
用浏览器来接收C# 的程序返回的时间cool!
DataGrid巧用实现目录浏览
asp+中常用的NameSpace的讲解
随机函数生成密码的asp.net版本
强大的数组功能(asp+程序数组功能调用)
如何用asp+获取post的页面的数据
asp+版本简单的留言板的制作(一)
asp+版本简单的留言板的制作(二)
asp+版本简单的留言板的制作(三)
如何在服务器上保存一定时间的信息
一个功能完善的专栏管理的程序->这是asp.net的第二个应用(一)
一个功能完善的专栏管理的程序->这是asp.net的第二个应用(二)
一个功能完善的专栏管理的程序->这是asp.net的第二个应用(三)
这是asp.net的第二个应用(四)
这是asp.net的第二个应用(五)

ASP.NET 中的 asp.net中的vb7中如何使用socket作一个传送时间的server


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 26 ::
收藏到网摘: n/a

/*
豆腐制作,都是精品
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