tinyweb 有什么用_TinyWeb:C#中的简单Web服务器

聂建茗
2023-12-01

tinyweb 有什么用

Note: This project only serves single requests at once. Try this one instead. It's better: Tiny Web Server Take 2

注意:此项目一次只能处理单个请求。 试试这个吧。 更好: Tiny Web Server Take 2

介绍 (Introduction)

Currently, the offerings for .NET enabled web servers are platform dependent, and large, intended for scalable sites. Often, they have reams of features and lots of configuration. The simplest offering, http.sys, only works on windows.

当前,支持.NET的Web服务器的产品依赖于平台,并且规模较大,旨在用于可伸缩站点。 通常,它们具有大量功能和大量配置。 最简单的产品http.sys仅适用于Windows。

The purpose of this web server is to expose a small, limited scalability server for something like a home network, or another scenario where the connection frequency is relatively low, and users are trusted.

该Web服务器的目的是为家庭网络或连接频率相对较低且用户受信任的其他情况提供小型,可扩展性有限的服务器。

It works on any .NET platform, and its component based API is simple to operate. Just drag it onto a form or a service component, wire up the events, and set the properties. Aside from the local endpoint to listen on, there is zero configuration.

它可以在任何.NET平台上运行,并且其基于组件的API操作简单。 只需将其拖动到表单或服务组件上,连接事件并设置属性。 除了要侦听的本地端点外,配置为零。

使用代码 (Using the Code)

Using the code is fairly simple:

使用代码非常简单:

using TinyWeb;
using System.Net;
...
var webServer = new WebServer(); 
webServer.ProcessRequest += new ProcessRequestEventHandler(webServer_ProcessRequest);
webServer.EndPoint = new IPEndPoint(IPAddress.Any,8080);
webServer.IsStarted = true;
...
void webServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
{
    var r = args.Response;
    r.ContentType = "text/html";
    r.WriteLine("<html><h1>Hello World!</h1></html>");
}

Request has methods for getting the headers, the querystring, and the request/post stream. Response has methods for setting the response headers, and for writing the response stream.

Request具有获取标头,查询字符串和请求/发布流的方法。 Response具有用于设置响应头和写入响应流的方法。

兴趣点 (Points of Interest)

SocketUtility contains many other methods for working with sockets, especially asynchronous socket communication, including exposing awaitable methods for the primary socket operations.

SocketUtility包含许多其他用于套接字的方法,尤其是异步套接字通信,包括公开主要套接字操作的等待方法。

翻译自: https://www.codeproject.com/Tips/5165870/TinyWeb-A-Simple-Web-Server-in-Csharp

tinyweb 有什么用

 类似资料: