xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 3KB
    文件類型: .7z
    金幣: 1
    下載: 1 次
    發(fā)布日期: 2021-05-14
  • 語(yǔ)言: C#
  • 標(biāo)簽: httplistener??高并發(fā)??C#??

資源簡(jiǎn)介

C#調(diào)用httplistener實(shí)現(xiàn)簡(jiǎn)單的http服務(wù)器例子:編譯后是一個(gè)控制臺(tái)應(yīng)用程序,啟動(dòng)后,可通過(guò) http://127.0.0.1/ 訪問(wèn),采用了回調(diào)模式提供http服務(wù),支持高并發(fā)

資源截圖

代碼片段和文件信息


using?System;
using?System.Collections.Generic;
using?System.Linq;
using?System.Text;
using?System.Net;
using?System.Net.Sockets;
using?System.IO;
using?System.Web;

namespace?ConsoleApplication1
{
????class?Program
????{
????????static?HttpListener?sSocket?=?null;
????????public?static?string?modulePath;

????????static?void?Main(string[]?args)
????????{
????????????sSocket?=?new?HttpListener();
????????????sSocket.Prefixes.Add(“http://127.0.0.1:80/“);
????????????sSocket.Start();
????????????sSocket.BeginGetContext(new?AsyncCallback(GetContextCallBack)?sSocket);

????????????modulePath?=?System.AppDomain.CurrentDomain.baseDirectory;
????????????Console.WriteLine(“modulePath?:?“+modulePath+“\n“);
????????????Console.Read();
????????}

????????static?void?GetContextCallBack(IAsyncResult?ar)
????????{
????????????try
????????????{
????????????????sSocket?=?ar.AsyncState?as?HttpListener;
????????????????HttpListenerContext?context?=?sSocket.EndGetContext(ar);
????????????????sSocket.BeginGetContext(new?AsyncCallback(GetContextCallBack)?sSocket);
????????????????HttpListenerRequest?request?=?context.Request;
????????????????HttpListenerResponse?response?=?context.Response;
????????????????Console.WriteLine(request.Url.PathAndQuery);

????????????????string?username?=?HttpUtility.ParseQueryString(request.Url.Query).Get(“username“);
????????????????string?pwd?=?HttpUtility.ParseQueryString(request.Url.Query).Get(“pwd“);

????????????????string?absPath?=?request.Url.AbsolutePath.Substring(1);
????????????????Console.WriteLine(“absPath:“+absPath);

????????????????if?(absPath?==?“favicon.ico“)
????????????????{
????????????????????string?filename=Path.Combine(modulePathabsPath);
????????????????????if(File.Exists(filename))
????????????????????{
????????????????????????try
????????????????????????{
????????????????????????????Console.WriteLine(“Process?ico“);
????????????????????????????Stream?input?=?new?FileStream(filename?FileMode.Open);
????????????????????????????string?mime?=?“image/x-icon“;
????????????????????????????response.ContentType?=?mime;
????????????????????????????response.ContentLength64?=?input.Length;
????????????????????????????response.AddHeader(“Date“?DateTime.Now.ToString(“r“));
????????????????????????????response.AddHeader(“Last-Modified“?File.GetLastWriteTime(filename).ToString(“r“));

????????????????????????????byte[]?obuffer?=?new?byte[1024?*?32];
????????????????????????????int?nbytes;
????????????????????????????while?((nbytes?=?input.Read(obuffer?0?obuffer.Length))?>?0)
????????????????????????????{
????????????????????????????????response.OutputStream.Write(obuffer?0?nbytes);
????????????????????????????}
????????????????????????????
????????????????????????????input.Close();
????????????????????????????response.OutputStream.Flush();
????????????????????????????response.StatusCode?=?(int)HttpStatusCode.OK;
????????????????????????????obuff

評(píng)論

共有 條評(píng)論