是否对的HttpListener工作单吗? [英] Does HttpListener work well on Mono?

查看:159
本文介绍了是否对的HttpListener工作单吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我期待写一个小Web服务上的一个小的Linux机器上运行。我更喜欢在C#中的代码,所以我希望使用单声道。

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服务器或单声道的版本的ASP的开销。净。我想有一个线程处理每个客户端连接单个进程。线程而不是数据库之间共享内存。

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.

我读过关于微软版本的HttpListener以及它是如何工作的Http.sys驱动程序一点点。唉,单就这一类的文档只是自动化类接口,没有它是如何工作的引擎盖下讨论。 (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.)

前段时间,我问的这个问题,有志于保持长时间的谈话,有很多回,来回开。我已经在设计自己的临时协议解决,但人们我跟真的想要一个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 /单声道服务器上运行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.

推荐答案

问候,
单声道的HttpListener类的工作没有太大的问题。我认为,其在MS环境和Linux环境中使用的最显著不同的是,80端口不能没有根/苏/ sudo的安全绑定。其他端口没有此限制。例如,如果您指定的前缀:的http://本地主机:1234 / 中的HttpListener按预期工作。不过,如果你添加前缀的http://本地主机/ ,你会希望监听80端口,它静静地失败。如果你试图明确绑定到80端口(HTTP://本地主机:80 /),则抛出异常。如果调用应用程序以超级用户或根,你可以明确地绑定到80端口(HTTP://本地主机: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.

chickenSandwich

chickenSandwich

这篇关于是否对的HttpListener工作单吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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