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

明輝手游網(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;
}
}
呵呵,一頭霧水??我也累了,明天再回答大家的問題吧!





主站蜘蛛池模板: 欧美亚洲免费久久久 | 亚洲欧美人妖另类激情综合区 | 色黄网址 | 日韩中文一区 | 中文黄色 | 青青草原国产在线观看 | 天天狠狠色噜噜 | 欧美怡红院免费全部视频 | 又粗又大又硬又爽的免费视频 | 日日夜夜免费视频 | 日韩在线a视频免费播放 | 亚洲九九香蕉 | 日日摸夜夜爽夜夜爽出水 | 在线视频欧美日韩 | 亚洲综合色丁香婷婷六月图片 | 婷婷激情五月网 | 亚洲国产成人久久一区www | 欧美在线一区二区 | 天天天天天天天操 | 中文字幕视频在线 | 四虎国产永久在线精品免费观看 | 羞羞漫画弹窗 | 日韩欧美一及在线播放 | 日韩欧美二区在线观看 | 日本欧洲亚洲一区在线观看 | 一级一级女人真片 | 中日韩欧美视频 | 午夜网站在线观看免费网址免费 | 无码日韩精品一区二区免费 | 在线观看精品自拍视频 | 在线观看亚洲免费视频 | 亚洲伊人成综合人影院小说 | 亚洲免费网站观看视频 | 亚洲 欧美 清纯 丝袜 另类 | 爽爽影院在线看 | 亚州三级 | 色综合久久精品中文字幕 | 手机看片日韩日韩韩 | 日本卡一卡2卡3卡4精品卡无人区 | 欧美在线1 | 日韩高清一级毛片 |