人人做人人澡人人爽欧美,国产主播一区二区,久久久精品五月天,羞羞视频在线观看免费

當(dāng)前位置:蘿卜系統(tǒng)下載站 > 技術(shù)開(kāi)發(fā)教程 > 詳細(xì)頁(yè)面

用瀏覽器來(lái)接收C# 的程序返回的時(shí)間

用瀏覽器來(lái)接收C# 的程序返回的時(shí)間

更新時(shí)間:2022-07-18 文章作者:未知 信息來(lái)源:網(wǎng)絡(luò) 閱讀次數(shù):

今天早上 我寫了一篇 用socket 做的 時(shí)間服務(wù)器,當(dāng)時(shí)我說(shuō)準(zhǔn)備用一段時(shí)間作個(gè)不需要客戶端接收數(shù)據(jù)
而是用 瀏覽器 接收數(shù)據(jù)的程序,很順利,一天的時(shí)間 我就做好了:)
閑話不說(shuō),先看程序。。。

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;
}
}

溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!

本類教程下載

系統(tǒng)下載排行

網(wǎng)站地圖xml | 網(wǎng)站地圖html
主站蜘蛛池模板: 茌平县| 怀柔区| 磐石市| 通州市| 新郑市| 崇州市| 黎平县| 桓台县| 南投市| 阿尔山市| 扶沟县| 佛学| 阳原县| 新泰市| 瑞安市| 科尔| 东乡| 于都县| 高密市| 隆化县| 京山县| 侯马市| 清流县| 太白县| 扎鲁特旗| 江安县| 博乐市| 凤山市| 苗栗县| 买车| 库车县| 长顺县| 天气| 奉化市| 甘孜县| 哈尔滨市| 毕节市| 昌平区| 宜阳县| 临沭县| 蓬安县|