blob: 5471d3aebdd83055fbb6b61fb2414aa5c47d4205 [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>,
Andy Greence510c62010-11-11 12:48:13 +00005<i>int (*</i><b>callback</b>) <i>(struct libwebsocket *, enum libwebsocket_callback_reasons, void *, void *, size_t)</i>,
Andy Green3faa9c72010-11-08 17:03:03 +00006<i>size_t</i> <b>user_area_size</b>,
7<i>const char *</i> <b>ssl_cert_filepath</b>,
8<i>const char *</i> <b>ssl_private_key_filepath</b>,
9<i>int</i> <b>gid</b>,
10<i>int</i> <b>uid</b>)
Andy Green62a12932010-11-03 11:19:23 +000011<h3>Arguments</h3>
12<dl>
13<dt><b>port</b>
14<dd>Port to listen on
15<dt><b>callback</b>
16<dd>The callback in user code to perform actual serving
Andy Green62a12932010-11-03 11:19:23 +000017<dt><b>user_area_size</b>
18<dd>How much memory to allocate per connection session
19which will be used by the user application to store
20per-session data. A pointer to this space is given
21when the user callback is called.
Andy Green3faa9c72010-11-08 17:03:03 +000022<dt><b>ssl_cert_filepath</b>
23<dd>If libwebsockets was compiled to use ssl, and you want
24to listen using SSL, set to the filepath to fetch the
25server cert from, otherwise NULL for unencrypted
26<dt><b>ssl_private_key_filepath</b>
27<dd>filepath to private key if wanting SSL mode,
28else ignored
29<dt><b>gid</b>
30<dd>group id to change to after setting listen socket, or -1.
31<dt><b>uid</b>
32<dd>user id to change to after setting listen socket, or -1.
Andy Green62a12932010-11-03 11:19:23 +000033</dl>
34<h3>Description</h3>
35<blockquote>
36This function forks to create the listening socket and takes care
37of all initialization in one step.
38<p>
39The callback function is called for a handful of events including
40http requests coming in, websocket connections becoming
41established, and data arriving; it's also called periodically to allow
42async transmission.
43<p>
44The server created is a simple http server by default; part of the
45websocket standard is upgrading this http connection to a websocket one.
46<p>
47This allows the same server to provide files like scripts and favicon /
48images or whatever over http and dynamic data over websockets all in
49one place; they're all handled in the user callback.
50</blockquote>
51<hr>
Andy Green62a12932010-11-03 11:19:23 +000052<h2>libwebsocket_write - Apply protocol then write data to client</h2>
53<i>int</i>
54<b>libwebsocket_write</b>
55(<i>struct libwebsocket *</i> <b>wsi</b>,
56<i>unsigned char *</i> <b>buf</b>,
57<i>size_t</i> <b>len</b>,
58<i>enum libwebsocket_write_protocol</i> <b>protocol</b>)
59<h3>Arguments</h3>
60<dl>
61<dt><b>wsi</b>
62<dd>Websocket instance (available from user callback)
63<dt><b>buf</b>
64<dd>The data to send. For data being sent on a websocket
65connection (ie, not default http), this buffer MUST have
66LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFORE the pointer
67and an additional LWS_SEND_BUFFER_POST_PADDING bytes valid
68in the buffer after (buf + len). This is so the protocol
69header and trailer data can be added in-situ.
70<dt><b>len</b>
71<dd>Count of the data bytes in the payload starting from buf
72<dt><b>protocol</b>
73<dd>Use LWS_WRITE_HTTP to reply to an http connection, and one
74of LWS_WRITE_BINARY or LWS_WRITE_TEXT to send appropriate
75data on a websockets connection. Remember to allow the extra
76bytes before and after buf if LWS_WRITE_BINARY or LWS_WRITE_TEXT
77are used.
78</dl>
79<h3>Description</h3>
80<blockquote>
81This function provides the way to issue data back to the client
82for both http and websocket protocols.
83<p>
84In the case of sending using websocket protocol, be sure to allocate
85valid storage before and after buf as explained above. This scheme
86allows maximum efficiency of sending data and protocol in a single
87packet while not burdening the user code with any protocol knowledge.
88</blockquote>
89<hr>
90<h2>libwebsockets_serve_http_file - Send a file back to the client using http</h2>
91<i>int</i>
92<b>libwebsockets_serve_http_file</b>
93(<i>struct libwebsocket *</i> <b>wsi</b>,
94<i>const char *</i> <b>file</b>,
95<i>const char *</i> <b>content_type</b>)
96<h3>Arguments</h3>
97<dl>
98<dt><b>wsi</b>
99<dd>Websocket instance (available from user callback)
100<dt><b>file</b>
101<dd>The file to issue over http
102<dt><b>content_type</b>
103<dd>The http content type, eg, text/html
104</dl>
105<h3>Description</h3>
106<blockquote>
107This function is intended to be called from the callback in response
108to http requests from the client. It allows the callback to issue
109local files down the http link in a single step.
110</blockquote>
111<hr>