views:

228

answers:

2

Hi everyone. 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.

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.

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?

Many thanks, Bill, billpg.com

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

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.

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.

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.

A: 

I am not sure why you want to look so deep into the hood. Even on Microsoft side, the documents about http.sys may not provide you really valuable information if you are using the .NET Framework.

To know if something works on Mono good enough, you are always supposed to download its VMware or VPC image, and test your applications on it.

http://www.go-mono.com/mono-downloads/download.html

Though Mono is much more mature than a few years ago, we cannot say it has been tested by enough real-world applications like Microsoft.NET. So please test out your applications and submit issues you find to Mono team.

Based on my experience, minor issues are fixed within only a few days, while for major issues it takes a longer time. But with Mono source code available, you can fix on your own or find out good workarounds most of the times.

Lex Li
Many thanks Lex.I was expecting Microsoft's version of the library to open a socket-listen and perform some header parsing. I wasn't expecting a kernel module running in ring 0.If Mono's version also uses a kernel module, it will inform any engineering decisions I need to make.
billpg
Http.sys first appears in Windows Server 2003 to improve performance and provide new features. But it does not change HttpListener API, right? HttpListener still works on Windows XP where http.sys does not exist. This also applies to Mono, where the underlying OS may or may not have a http.sys alike module. As far as I know, in such case Mono team tries to provide many backends and one of them will be picked up at runtime based on OS/modules it detects. Check out this similar case, "What are the issues with FileSystemWatcher?" in http://www.mono-project.com/FAQ:_Technical
Lex Li
+1  A: 

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