blob: a75ddb26a18ef567a603c9050af6475ac825e47b [file] [log] [blame]
Andy Green62a12932010-11-03 11:19:23 +00001<h2>libwebsocket_create_server - Create the listening websockets server</h2>
2<i>int</i>
3<b>libwebsocket_create_server</b>
4(<i>int</i> <b>port</b>,
5<i>int (*</i><b>callback</b>) <i>(struct libwebsocket *, enum libwebsocket_callback_reasons, void *, void *, size_t)</i>,
6<i>int</i> <b>protocol</b>,
7<i>size_t</i> <b>user_area_size</b>)
8<h3>Arguments</h3>
9<dl>
10<dt><b>port</b>
11<dd>Port to listen on
12<dt><b>callback</b>
13<dd>The callback in user code to perform actual serving
14<dt><b>protocol</b>
15<dd>Which version of the websockets protocol (currently 76)
16<dt><b>user_area_size</b>
17<dd>How much memory to allocate per connection session
18which will be used by the user application to store
19per-session data. A pointer to this space is given
20when the user callback is called.
21</dl>
22<h3>Description</h3>
23<blockquote>
24This function forks to create the listening socket and takes care
25of all initialization in one step.
26<p>
27The callback function is called for a handful of events including
28http requests coming in, websocket connections becoming
29established, and data arriving; it's also called periodically to allow
30async transmission.
31<p>
32The server created is a simple http server by default; part of the
33websocket standard is upgrading this http connection to a websocket one.
34<p>
35This allows the same server to provide files like scripts and favicon /
36images or whatever over http and dynamic data over websockets all in
37one place; they're all handled in the user callback.
38</blockquote>
39<hr>
40<h2>libwebsocket_get_uri - Return the URI path being requested</h2>
41<i>const char *</i>
42<b>libwebsocket_get_uri</b>
43(<i>struct libwebsocket *</i> <b>wsi</b>)
44<h3>Arguments</h3>
45<dl>
46<dt><b>wsi</b>
47<dd>Websocket instance
48</dl>
49<h3>Description</h3>
50<blockquote>
51The user code can find out the local path being opened from this
52call, it's valid on HTTP or established websocket connections.
53If the client opened the connection with "http://127.0.0.1/xyz/abc.d"
54then this call will return a pointer to "/xyz/abc.d"
55</blockquote>
56<hr>
57<h2>libwebsocket_write - Apply protocol then write data to client</h2>
58<i>int</i>
59<b>libwebsocket_write</b>
60(<i>struct libwebsocket *</i> <b>wsi</b>,
61<i>unsigned char *</i> <b>buf</b>,
62<i>size_t</i> <b>len</b>,
63<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
64<h3>Arguments</h3>
65<dl>
66<dt><b>wsi</b>
67<dd>Websocket instance (available from user callback)
68<dt><b>buf</b>
69<dd>The data to send. For data being sent on a websocket
70connection (ie, not default http), this buffer MUST have
71LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
72and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
73in the buffer after (buf + len). This is so the protocol
74header and trailer data can be added in-situ.
75<dt><b>len</b>
76<dd>Count of the data bytes in the payload starting from buf
77<dt><b>protocol</b>
78<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
79of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
80data on a websockets connection. Remember to allow the extra
81bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
82are used.
83</dl>
84<h3>Description</h3>
85<blockquote>
86This function provides the way to issue data back to the client
87for both http and websocket protocols.
88<p>
89In the case of sending using websocket protocol, be sure to allocate
90valid storage before and after buf as explained above. This scheme
91allows maximum efficiency of sending data and protocol in a single
92packet while not burdening the user code with any protocol knowledge.
93</blockquote>
94<hr>
95<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
96<i>int</i>
97<b>libwebsockets_serve_http_file</b>
98(<i>struct libwebsocket *</i> <b>wsi</b>,
99<i>const char *</i> <b>file</b>,
100<i>const char *</i> <b>content_type</b>)
101<h3>Arguments</h3>
102<dl>
103<dt><b>wsi</b>
104<dd>Websocket instance (available from user callback)
105<dt><b>file</b>
106<dd>The file to issue over http
107<dt><b>content_type</b>
108<dd>The http content type, eg, text/html
109</dl>
110<h3>Description</h3>
111<blockquote>
112This function is intended to be called from the callback in response
113to http requests from the client. It allows the callback to issue
114local files down the http link in a single step.
115</blockquote>
116<hr>