Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetty for NET world

Tags:

c#

.net

f#

managed

I am looking for the Jetty equivalent in the Net Framework world - managed code. Does it exist? I would like to use the library from an F#/C#/VB.net application. "Don't deploy your application in Jetty, deploy Jetty in your application."

like image 952
dag Avatar asked Nov 08 '12 14:11

dag


People also ask

What is Jetty server used for?

Jetty provides a web server and servlet container, additionally providing support for HTTP/2, WebSocket, OSGi, JMX, JNDI, JAAS and many other integrations. These components are open source and are freely available for commercial use and distribution.

What is Jetty process?

Jetty is a Java HTTP (Web) server and Java Servlet container. Developed as a free and open source project as part of the Eclipse Foundation, Jetty is now often used for machine to machine communications, usually within larger software frameworks.

How do I download Jetty?

Download Jetty from https://www.eclipse.org/jetty/download.html and extract the zip file somewhere to your filesystem. This update site contains also a Eclipse p2 update site, in case you want to use Jetty in an OSGi environment.

How do you set up a Jetty?

Jetty POJO Configuration You can achieve this either by: Writing Java code to directly instantiate and assemble Jetty objects. This is referred to as Embedding Jetty. Using Jetty XML configuration, which is an Inversion of Control (IoC) framework, to instantiate and assemble Jetty objects as XML objects.


2 Answers

How sophisticated API are you looking for? For simple tasks, I think you can get fairly far just by using the standard HttpListener type. There is an MSDN sample that encapsulates it with an F# agent (part 3) and then uses it to create a simple chat server (part 4).

The core part of the chat server looks fairly straightforward:

let handleRequest (context:HttpListenerContext) = async { 
    match context.Request.Url.LocalPath with 
    | "/post" -> 
        // Send message to the chat room
        room.SendMessage(context.Request.InputString)
    | "/chat" -> 
        // Get messages from the chat room (asynchronously!)
        let! text = room.AsyncGetContent()
        context.Response.Reply(text)
    | s ->
        // Omitted: handle file request }

A more advanced library available for F# might be Frack (An implementation of the Open Web Interface for .NET (OWIN), a .NET Web Server Gateway Interface, written in F#.) This also looks very easy to use.

like image 91
Tomas Petricek Avatar answered Oct 04 '22 16:10

Tomas Petricek


ServiceStack also runs inside a self-hosted HttpListener application in Win/.NET or Mono/Linux (in addition to an ASP.NET host).

See the self-hosted wiki page for simple examples of running ServiceStack in a C# or F# Console apps.

like image 25
mythz Avatar answered Oct 04 '22 17:10

mythz