> For the complete documentation index, see [llms.txt](https://wsocket.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wsocket.gitbook.io/docs/master.md).

# Wsocket

[![Downloads](https://pepy.tech/badge/wsocket)](https://pepy.tech/project/wsocket)

{% hint style="info" %}
**Note:** I am a 16 years old student.I have no enough knowledge. So can anyone [help me](https://github.com/Ksengine/WSocket/issues/2) to develop this library?
{% endhint %}

{% content-ref url="/pages/-MMsS0RseWot1I2iYoPI" %}
[Installation](/docs/installation.md)
{% endcontent-ref %}

{% content-ref url="/pages/-MMGi-BHr6oFz\_7r-02Q" %}
[App](/docs/guide/app.md)
{% endcontent-ref %}

## Server

Server([WSGI](http://www.wsgi.org/)) creates and listens at the HTTP socket, dispatching the requests to a handler. [WSGIRef server](https://docs.python.org/3/library/wsgiref.html#wsgiref.simple_server.WSGIServer) but uses threads to handle requests by using the [ThreadingMixIn](https://docs.python.org/3/library/socketserver.html#socketserver.ThreadingMixIn). This is useful to handle web browsers pre opening sockets, on which Server would wait indefinitely.&#x20;

**can used with any WSGI compatible web framework**

## Middleware

convert any WSGI compatible web framework to Websocket+HTTP framework using middleware.

**works with many WSGI compatible servers** **and any WSGI compatible web framework**

{% hint style="info" %}
Flask, Django, Pyramid, Bottle, ... supported
{% endhint %}

> ## Handler

[`wsgiref.simple_server.WSGIRequestHandler`](https://docs.python.org/3/library/wsgiref.html#wsgiref.simple_server.WSGIRequestHandler) like class named `WebSocketHandler` that always wrap WSGI app using Middleware.

changes from `WSGIRequestHandler` :

* Prevents reverse DNS lookups
* error less logger
* Inherited from `FixedHandler`(fixed HTTP handler)
* uses `FixedServerHandler`  to make it WSGI

> You can convert wsgiref to a websocket+HTTP server using this handler

### ServerHandler

`wsgiref.simple_server.ServerHandler`(inherited from [`wsgiref.handlers.ServerHandler`](https://docs.python.org/3/library/wsgiref.html#wsgiref.handlers.SimpleHandler) ) like handler named `FixedServerHandler` .

changes from `ServerHandler` :

* set HTTP version to `1.1` because versions below `1.1` are not supported some clients like Firefox.

{% hint style="info" %}
This is a little hack. report any errors to [Issue Tracker](https://github.com/Ksengine/WSocket/issues/new)
{% endhint %}

* removed hop-by-hop headers checker because it raise errors on `Upgrade`  and `Connection` headers
* check that all headers are strings

## Framework

basic WSGI web application framework that uses Middleware.

* simple routes handler
* auto description to status code
* headers checker
* send data as soon as possible
* send strings, bytes, lists(even bytes and strings mixed) or files directly&#x20;
* error catcher and error logger

**works with many WSGI compatible servers**

## App

Event based app for websocket communication. this is app that uses Framework if not events handled by developer. this app works like demo(echo) app.

## Features

all Middleware, Handler, Framework and App has following features.

* websocket sub protocol supported
* websocket message compression supported (works if client asks)
* receive and send pong and ping messages(with automatic pong sender)
* receive and send binary or text messages
* works for messages with or without mask
* closing messages supported
* auto and manual close

## More

**Guide -** View [Documentaion](< https://wsocket.gitbook.io/ >) for examples and API reference.&#x20;

**Report** - bugs and ideas on Github [issue tracker](< https://github.com/Ksengine/WSocket/issues/>)

**License** - Code and documentation are available according to the MIT License (see [LICENSE](https://github.com/Ksengine/WSocket/blob/master/LICENSE)).
