dotnetcore Http服务器研究(一)


自从dotnet core 诞生以来,发展很是强势。咱们总有些须要写一个独立的http服务器的需求,我想是时候忘记httplistener 了。git


dotnet framework 时代建一个小的http服务器 最经常使用的工具就是 HttpListener了。github

如今是dotnet core的时代,asp.net 也有了一个官方提供的 selfhost 实现 kestrel服务器


咱们来研究一下kestrel的aspnetcore 怎么用app


他的基本使用很是简单,任意建立一个dotnet core项目asp.net

首先nuget 引用以下库工具

image

microsoft.aspnetcore.app.net

microsoft.aspnetcore.server.kestrel3d

你在网上看到的asp.net core的代码都是链式调用,我不是很喜欢这种写法,可是没办法,这个每个操做以后,host对象其实会发生变化,拆开写就得写一堆host=server

image

aspnetcore的基本使用方法就是这样,代码你能够找到不少,想看代码直接去个人仓库吧对象

https://github.com/lightszero/lightchain

相关文章
相关标签/搜索