六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

用瀏覽器來接收C# 的程序返回的時間cool!

[摘要]/*豆腐制作 都是精品http://www.asp888.net 豆腐技術(shù)站如轉(zhuǎn)載 請保留版權(quán)信息*/今天早上 我寫了一篇 用socket 做的 時間服務(wù)器,當(dāng)時我說準(zhǔn)備用一段時間作個不需要客戶端接...
/*
豆腐制作 都是精品
http://www.asp888.net 豆腐技術(shù)站
如轉(zhuǎn)載 請保留版權(quán)信息
*/
今天早上 我寫了一篇 用socket 做的 時間服務(wù)器,當(dāng)時我說準(zhǔn)備用一段時間作個不需要客戶端接收數(shù)據(jù)
而是用 瀏覽器 接收數(shù)據(jù)的程序,很順利,一天的時間 我就做好了:)
閑話不說,先看程序。。。

using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;

class HttpProcessor {

private Socket s;
private BufferedStream bs;
private StreamReader sr;
private StreamWriter sw;
private String method;
private String url;
private String protocol;
private Hashtable hashTable;

public HttpProcessor(Socket s) {
this.s = s;
hashTable = new Hashtable();
}

public void process() {
NetworkStream ns = new NetworkStream(s, FileAccess.ReadWrite);
bs = new BufferedStream(ns);
sr = new StreamReader(bs);
sw = new StreamWriter(bs);
writeURL();
s.Shutdown(SocketShutdown.SdBoth);
ns.Close();
}
public void writeURL() {
try {
writeSuccess();
} catch(FileNotFoundException) {
writeFailure();
sw.WriteLine("File not found: " + url);
}
sw.Flush();
}

public void writeSuccess() {
sw.WriteLine("HTTP/1.1 200 OK");
sw.WriteLine("Server: Microsoft-IIS/5.0");
sw.WriteLine("Date: Mon, 27 Nov 2000 08:19:43 GMT");
sw.WriteLine("Content-Length: 6");
sw.WriteLine("Content-Type: text/html");
sw.WriteLine("");

String strDateLine;
DateTime now;
now = DateTime.Now;
strDateLine = now.ToShortDateString() + " " + now.ToLongTimeString();
sw.WriteLine(strDateLine);
}

public void writeFailure() {
sw.WriteLine("HTTP/1.0 404 File not found");
sw.WriteLine("Connection: close");
sw.WriteLine();
}
}

public class HttpServer {
public HttpServer() : this(81) {
}

public HttpServer(int port) {
this.port = port;
}
public void listen() {
Socket listener = new Socket(0, SocketType.SockStream, ProtocolType.ProtTCP);
IPAddress ipaddress = new IPAddress("169.254.0.244");
IPEndPoint endpoint = new IPEndPoint(ipaddress, port);
listener.Bind(endpoint);
listener.Blocking = true;
listener.Listen(-1);
Console.WriteLine("Press Ctrl+c to Quit...");
while(true) {
Socket s = listener.Accept();
HttpProcessor processor = new HttpProcessor(s);
Thread thread = new Thread(new ThreadStart(processor.process));
thread.Start();
}
}
public static int Main(String[] args) {
HttpServer httpServer;
if(args.GetLength(0) > 0) {
httpServer = new HttpServer(args[0].ToUInt16());
} else {
httpServer = new HttpServer();
}
Thread thread = new Thread(new ThreadStart(httpServer.listen));
thread.Start();
return 0;
}
}
呵呵,一頭霧水??我也累了,明天再回答大家的問題吧!





主站蜘蛛池模板: 亚洲一区二区在线成人 | 日本高清色本在线www游戏 | 四虎一影院区永久精品 | 香蕉视频导航 | 日本高清免费一本视频无需下载 | 亚洲性久久久影院 | 亚洲欧美男人天堂 | 色狠狠成人综合网 | 欧美性xxxxx极品 | 中文字幕在线视频精品 | 中文字幕专区高清在线观看 | 偷拍免费视频 | 天天操天天舔 | 伊人久久综合成人网小说 | 亚洲欧美日韩高清一区二区一 | 日本wwwxx| 欧美怡红院免费全部视频 | 人人鲁免费播放视频人人香蕉 | 日本成人福利视频 | 日韩综合nv一区二区在线观看 | 青青国产在线播放 | 亚洲香蕉综合在人在线视看 | 婷婷视频网站 | 亚洲精品视频网 | 日日摸夜夜爽人人添 | 亚洲s色大片在线观看下载 亚洲s色 | 亚洲日本欧美 | 亚洲美女视频一区 | 日韩视频免费在线 | 日韩欧美中文字幕一区 | 视频免费1区二区三区 | 日本一道在线观看 | 思思99re66在线精品免费观看 | 亚洲成a| 午夜在线影院 | 婷婷色中文网 | 青青草99热这里都是精品 | 亚洲天堂一区二区 | 色橹橹欧美在线观看高清视频 | 欧美亚洲国产精品久久高清 | 手机国产乱子伦精品视频 |