{"id":21093306,"url":"https://github.com/1iveowl/simple-http-listener-pcl","last_synced_at":"2025-10-09T21:35:10.303Z","repository":{"id":65414457,"uuid":"58945937","full_name":"1iveowl/Simple-Http-Listener-PCL","owner":"1iveowl","description":"Simple Http Server PCL for Xamarin Forms","archived":false,"fork":false,"pushed_at":"2019-09-21T10:22:50.000Z","size":41814,"stargazers_count":39,"open_issues_count":1,"forks_count":6,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-08-16T22:46:58.937Z","etag":null,"topics":["csharp","http","http-server","xamarin"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/1iveowl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"https://www.buymeacoffee.com/fEXda8L"}},"created_at":"2016-05-16T15:57:27.000Z","updated_at":"2024-05-30T02:18:18.000Z","dependencies_parsed_at":"2023-01-22T10:15:25.691Z","dependency_job_id":null,"html_url":"https://github.com/1iveowl/Simple-Http-Listener-PCL","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/1iveowl/Simple-Http-Listener-PCL","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1iveowl%2FSimple-Http-Listener-PCL","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1iveowl%2FSimple-Http-Listener-PCL/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1iveowl%2FSimple-Http-Listener-PCL/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1iveowl%2FSimple-Http-Listener-PCL/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/1iveowl","download_url":"https://codeload.github.com/1iveowl/Simple-Http-Listener-PCL/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/1iveowl%2FSimple-Http-Listener-PCL/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279002051,"owners_count":26083286,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","http","http-server","xamarin"],"created_at":"2024-11-19T22:01:29.819Z","updated_at":"2025-10-09T21:35:10.287Z","avatar_url":"https://github.com/1iveowl.png","language":"C#","funding_links":["https://www.buymeacoffee.com/fEXda8L"],"categories":[],"sub_categories":[],"readme":"# Important\nThis library has been replaced with version 6.0: [Simple Http Listener Rx](https://github.com/1iveowl/SimpleHttpListener.Rx/blob/master/README.md). Please use this newer and better version. \n\nThank you.\n\n# Simple Http Listener\n\n\n[![NuGet Badge](https://buildstats.info/nuget/SimpleHttpListener.Rx)](https://www.nuget.org/packages/SimpleHttpListener.Rx/)\n\nPrevious versions:\n\n[![NuGet Badge](https://buildstats.info/nuget/SimpleHttpListener)](https://www.nuget.org/packages/SimpleHttpListener)\n\n*Please star this project if you find it useful. Thank you.*\n\n[![.NET Standard](http://img.shields.io/badge/.NET_Standard-v2.0-green.svg)](https://docs.microsoft.com/da-dk/dotnet/articles/standard/library)\n\nVersion 6.0 has breaking change but is also a great improvement to previous versions. Using version 6.0 is highly recommended. \n\n## What is this?\nThis is the legacy version of Simple HTTP Listener, which is a a simple Http Listener that is created as a Portable Class Library and to works with Xamarin Forms across Windows 10, iOS and Android.\n\nThis project is based on [SocketLite.PCL](https://github.com/1iveowl/sockets-for-pcl/) for cross platform TCP sockets support. \n\nIMPORTANT: SocketList.PCL utilizes the \"Bait and Switch\" pattern and the SocketLite.PCL nuget must be part of any project using Simple Http Listner PCL.\n\nThe Http Listener also requires Microsoft [Reactive Extensions](https://www.nuget.org/packages/Rx-Main). \n\n## Version 5.0\nFrom version 5.0 and onwards, only .NET Standard 2.0 and later is supported.\n\n## Version 4.0\nVersion 4.0 represents a major overhaul of this library. Version 4.0 is still backwards compatible, but many of the methods have been marked as deprecated to inspire developers to use the newer versions of this library. In previous versions you had to subscribe to an observable and then start the action. In version 4.0 you just subscribe, that's it. Much more clean and better aligned with the Rx patterns.\n\nThere is still UWP support in version 4.0, but the emphasis has been on .NET Core and it will be going forward\n\n## How To Use \n\n### Using\nTo make sure that the HttpListner is not confused with the existing .NET HttpListner do like this:\n\n```cs\nusing HttpListener = SimpleHttpServer.Service.HttpListener;\n```\n\n### Get a Listener On An Interface\nTo make it even easier to get started an Initializer have been added. All you need to do to listen to a certain interface is:\n```csharp\nvar listenerConfig = Initializer.GetListener(\"192.168.0.2\", 8000);\n_httpListener = listenerConfig.httpListener;\n```\nNotice that the GetListener utilizes C# 7.0 and returns a tuple of type ```(IHttpListener, ICommunicationInterface)```\n\n### Start Observing Incomming Request\n\nTo use Http Requests all you need to do is something like this:\n\n```csharp\nvar observerListener = await _httpListener.TcpHttpRequestObservable(\n    port: 8000,\n    allowMultipleBindToSamePort: true);\n\nobserverListner.Subscribe(\n    async request =\u003e\n    {\n        //Enter your code handling each incoming Http request here.\n\n        // Example\n        System.Console.WriteLine($\"Remote Address: {request.RemoteAddress}\");\n        System.Console.WriteLine($\"Remote Port: {request.RemotePort}\");\n        System.Console.WriteLine(\"--------------***-------------\");\n\n        // Example responding back to the Http Request with telling the time:\n        if (request.RequestType == RequestType.TCP)\n        {\n            \n            var response = new HttpResponse\n            {\n                StatusCode = (int)HttpStatusCode.OK,\n                ResponseReason = HttpStatusCode.OK.ToString(),\n                Headers = new Dictionary\u003cstring, string\u003e\n                        {\n                            {\"Date\", DateTime.UtcNow.ToString(\"r\")},\n                            {\"Content-Type\", \"text/html; charset=UTF-8\" },\n                        },\n                Body = new MemoryStream(Encoding.UTF8.GetBytes($\"\u003chtml\u003e\\r\\n\u003cbody\u003e\\r\\n\u003ch1\u003eHello, World! {DateTime.Now}\u003c/h1\u003e\\r\\n\u003c/body\u003e\\r\\n\u003c/html\u003e\"))\n            };\n\n            await _httpListener.HttpSendReponseAsync(request, response).ConfigureAwait(false);\n        }\n    },\n    ex =\u003e\n    {\n        // Handle exceptions here\n    }, \n    () =\u003e \n    {\n        // Handle complete here. \n    });\n```\nYou need to create you own implementation of the `HttpResponse` class. You can call it whatever you want, but it MUST implement the `IHttpResponse` interface. It can look like this:\n\n```csharp\ninternal class HttpResponse : IHttpResponse\n{\n    public int MajorVersion { get; internal set; }\n    public int MinorVersion { get; internal set; }\n\n    public int StatusCode { get; internal set; }\n\n    public string ResponseReason { get; internal set; }\n    public IDictionary\u003cstring, string\u003e Headers { get; internal set; }\n\n    public MemoryStream Body { get; internal set; }\n\n\n    public string RemoteAddress { get; internal set; }\n    public int RemotePort { get; internal set; }\n    public RequestType RequestType { get; internal set; }\n    public ITcpSocketClient TcpSocketClient { get; internal set; }\n\n    public IDictionary\u003cstring, string\u003e ResonseHeaders { get; internal set; }\n\n    public bool IsEndOfRequest { get; internal set; }\n    public bool IsRequestTimedOut { get; internal set; }\n    public bool IsUnableToParseHttp { get; internal set; }\n}\n```\n\nThese steps are all you have to do to build a simple HttpServer that tells the time.\n\n### Listen To Other Http Requests/Responses\nYou can also listen to UDP and UDP Multicast.\n\nHere is the complete list of interfaces defining the differnt listeners:\n\n```csharp\nTask\u003cIObservable\u003cIHttpRequest\u003e\u003e TcpHttpRequestObservable(\n    int port,\n    bool allowMultipleBindToSamePort = true);\n\nTask\u003cIObservable\u003cIHttpResponse\u003e\u003e TcpHttpResponseObservable(\n    int port,\n    bool allowMultipleBindToSamePort = true);\n\n\nTask\u003cIObservable\u003cIHttpRequest\u003e\u003e UdpHttpRequestObservable(\n    int port,\n    bool allowMultipleBindToSamePort = true);\n\nTask\u003cIObservable\u003cIHttpResponse\u003e\u003e UdpHttpResponseObservable(\n    int port,\n    bool allowMultipleBindToSamePort = true);\n\nTask\u003cIObservable\u003cIHttpRequest\u003e\u003e UdpMulticastHttpRequestObservable(\n    string ipAddr,\n    int port,\n    bool allowMultipleBindToSamePort = true);\n\nTask\u003cIObservable\u003cIHttpResponse\u003e\u003e UdpMulticastHttpResponseObservable(\n    string ipAddr,\n    int port,\n    bool allowMultipleBindToSamePort = true);\n```\n\n\nFor full example look at the [Console .NET Core Example](https://github.com/1iveowl/Simple-Http-Listener-PCL/tree/master/src/test/Console.NETCore.Test).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1iveowl%2Fsimple-http-listener-pcl","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F1iveowl%2Fsimple-http-listener-pcl","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F1iveowl%2Fsimple-http-listener-pcl/lists"}