HttpListener 在 Mono 上运行良好吗? [英] Does HttpListener work well on Mono?

查看:23
本文介绍了HttpListener 在 Mono 上运行良好吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在小型 Linux 机器上运行的小型 Web 服务.我更喜欢用 C# 编写代码,所以我希望使用 Mono.

I'm looking to write a small web service to run on a small Linux box. I prefer to code in C#, so I'm looking to use Mono.

我不希望运行完整的 Web 服务器或 Mono 的 ASP.NET 版本的开销.我正在考虑使用一个线程处理每个客户端连接的单个进程.线程之间而不是数据库之间的共享内存.

I don't want the overhead of running a full web server or Mono's version of ASP.NET. I'm thinking of having a single process with a thread dealing with each client connection. Shared memory between threads instead of a database.

我已经阅读了一些关于 Microsoft 的 HttpListener 版本以及它如何与 Http.sys 驱动程序一起工作的内容.唉,Mono 关于这个类的文档只是自动化的类接口,没有讨论它是如何工作的.(Linux 没有 Http.sys,所以我想它的实现方式大不相同.)

I've read a little on Microsoft's version of HttpListener and how it works with the Http.sys driver. Alas, Mono's documentation on this class is just the automated class interface with no discussion of how it works under the hood. (Linux doesn't have Http.sys, so I imagine it's implemented substantially differently.)

谁能指点我一些讨论这个模块的资源?

Could anyone point me towards some resources discussing this module please?

非常感谢,比尔,billpg.com

Many thanks, Bill, billpg.com

(我的问题的一些背景知识.)

(A little background to my question for the interested.)

前段时间,我问了这个问题,有兴趣通过大量的来回保持长时间的对话.我已经决定设计自己的 ad-hoc 协议,但我与之交谈的人真的想要一个 REST 接口,即使以好的,现在发送你的命令"信号为代价.

Some time ago, I asked this question, interested in keeping a long conversation open with lots of back-and-forth. I had settled on designing my own ad-hoc protocol, but people I spoke to really wanted a REST interface, even at the cost of the "Okay, send your command now" signal.

所以,我想知道在 Linux/Mono 服务器上运行 ASP.NET,但偶然发现了 HttpListener.这似乎很理想,因为每个对话"都可以在单独的线程中运行.在循环中调用 HttpListener 的线程可以查找每个传入连接的线程,并将引用传递给该线程.

So, I wondered about running ASP.NET on a Linux/Mono server, but stumbled upon HttpListener. This seemed ideal, as each "conversation" could run in a separate thread. The thread that calls HttpListener in a loop can look for which thread each incomming connection is for and pass the reference to that thread.

ASP.NET 驱动服务的替代方法是让 ASPX 代码从数据库中获取状态,并在完成后写回新状态.是的,它会起作用,但开销很大.

The alternative for an ASP.NET driven service, would be to have the ASPX code pick up the state from a database, and write back the new state when it finishes. Yes, it would work, but that's a lot of overhead.

推荐答案

您好,Mono 中的 HttpListener 类可以正常工作.我认为它在 MS 环境和 Linux 环境中的使用之间最显着的区别是,如果没有 root/su/sudo 安全性,就无法绑定端口 80.其他端口没有这个限制.例如,如果您指定前缀:http://localhost:1234/,则 HttpListener 会按预期工作.但是,如果您添加前缀 http://localhost/,您希望在端口 80 上侦听,它会静默失败.如果您明确尝试绑定到端口 80 (http://localhost:80/),则会引发异常.如果您以超级用户或 root 身份调用应用程序,则可以显式绑定到端口 80 (http://localhost:80/).
我还没有足够详细地研究 HttpListener 的其余成员,以对它在 linux 环境中的运行情况发表任何有用的评论.但是,如果有兴趣,我会继续发表我的意见.

Greetings, The HttpListener class in Mono works without much of a problem. I think that the most significant difference between its usage in a MS environment and a Linux environment is that port 80 cannot be bound to without a root/su/sudo security. Other ports do not have this restriction. For instance if you specify the prefix: http://localhost:1234/ the HttpListener works as expected. However if you add the prefix http://localhost/, which you would expect to listen on port 80, it fails silently. If you explicitly attempt to bind to port 80 (http://localhost:80/) then you throw an exception. If you invoke your application as a super user or root, you can explicitly bind to port 80 (http://localhost:80/).
I have not yet explored the rest of the HttpListener members in enough detail to make any useful comments about how well it operates in a linux environment. However, if there is interest, I will continue to post my observations.

鸡肉三明治

这篇关于HttpListener 在 Mono 上运行良好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆