-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.c
45 lines (34 loc) · 900 Bytes
/
server.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <string.h>
#include "servkit.h"
static SERVKIT_SERVER server;
static SERVKIT_CLIENT client;
void client_accept(SERVKIT_CLIENT __client)
{
printf("Client connected to server\n");
client = __client;
}
void client_handler(SERVKIT_CLIENT __client, uint8_t *data, int len, void *arg)
{
}
void event(void *arg)
{
char msg[] = "Hello, world!";
int len = strlen(msg) + 1;
if (client) {
printf("Writing to client\n");
servkit_server_send_raw(server, client, msg, len);
}
}
int main(void)
{
servkit_init();
server = servkit_server_open("/tmp/server.sock", client_handler, NULL);
if (server) {
printf("Opened servkit server successfully\n");
}
servkit_server_install_connect_cb(server, client_accept);
servkit_addtimer(1000, SERVKIT_TIMER_RETRIGGER, event, NULL);
servkit_loop();
return 0;
}