Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nicholascok/webs
simple c89-compliant web-socket server library
https://github.com/nicholascok/webs
c89 websocket-server
Last synced: about 1 month ago
JSON representation
simple c89-compliant web-socket server library
- Host: GitHub
- URL: https://github.com/nicholascok/webs
- Owner: nicholascok
- Created: 2021-10-04T23:59:41.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-03-01T04:14:57.000Z (almost 3 years ago)
- Last Synced: 2024-10-25T22:31:05.294Z (3 months ago)
- Topics: c89, websocket-server
- Language: C
- Homepage:
- Size: 271 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# webs
a simple websocket server library.## Compilation
```
$ cc -o my_server webs.c my_server.c -lpthread
$ ./my_server
```## Events
| Event | Description |
|:-----------|:------------|
| `on_open` | called when a client connects to a server |
| `on_close` | called when a client disconnects from a server |
| `on_data` | called when data is recieved from a client |
| `on_error` | called when an error occurs |
| `on_pong` | called when a server recieves a pong |
| `on_ping` | called when a client pings a server |## Handlers
### `on_open`, `on_close`, `on_ping`, `on_pong`
###### Format
`int my_func(webs_client* self);`
| Parameter | Description |
|------------|-------------|
|`self` | client that triggered the event |### `on_data`
###### Format
`int my_func(webs_client* self, char* data, size_t length);`
| Parameter | Description |
|------------|-------------|
|`self` | client that triggered the event |
|`data` | pointer to recieved data |
|`length` | number of bytes recieved |**NOTE**: data is freed when the function returns, doing so yourself is ill-advised.
### `on_error`
###### Format
`int my_func(webs_client* self, enum webs_error code);`
| Parameter | Description |
|------------|-------------|
|`self` | client that triggered the event |
|`code` | error code |Possible value for `code` are,
```
WEBS_ERR_NONE, /* no error */
WEBS_ERR_READ_FAILED, /* failed to read data */
WEBS_ERR_UNEXPECTED_CONTINUTATION, /* recieved frame marked as continuation with
* no apparent start frame recieved */
WEBS_ERR_NO_SUPPORT, /* frame uses reserved opcode, no support */
WEBS_ERR_OVERFLOW /* frame attempted to contain more than SSIZE_MAX
* bytes of data */
```## Sending Data
### Strings
###### Format
`webs_send(self, string)`
| Parameter | Description |
|------------|-------------|
|`self` | client to send data to |
|`string` | null-terminated string |### Other
###### Format
`webs_sendn(self, data, length)`
| Parameter | Description |
|------------|-------------|
|`self` | client to send data to |
|`data` | pointer to data that is to be sent |
|`length` | number of bytes to be sent |## Shutting Down
### Disconnecting a Client
###### Format
`webs_eject(self)`
| Parameter | Description |
|------------|-------------|
|`self` | client to be ejected |### Stopping a Server
###### Format
`webs_close(server)`
| Parameter | Description |
|------------|-------------|
|`server` | server that is to be closed |### Blocking Until a Server Closes
###### Format
`webs_hold()`
| Parameter | Description |
|------------|-------------|
|`server` | server that is to be waited for |