using System;
using System.Net;
namespace HttpListening
{
public delegate void RequestReceivedEventHandler(HttpListenerContext context);
public class HttpWebServer:IDisposable
{
protected HttpListener _listener;
protected bool _isListenerOn;
public event RequestReceivedEventHandler OnRequestReceived;
public void StartListening(string[] urlCollection)
{
_isListenerOn = true;
_listener = new HttpListener();
foreach (var i in urlCollection) _listener.Prefixes.Add(i);
_listener.Start();
Action requestLoop = new Action(delegate
{
while (_isListenerOn)
{
_listener.BeginGetContext(new AsyncCallback(delegate (IAsyncResult ar)
{
OnRequestReceived(_listener.EndGetContext(ar));
}), null).AsyncWai
利用C#制作简单服务器
最新推荐文章于 2024-09-06 13:36:48 发布
本文档将介绍如何利用C#编程语言创建一个简单的服务器。通过实例代码和步骤解析,帮助读者理解C#在服务器开发中的应用。
摘要由CSDN通过智能技术生成