9
#include <netinet/in.h>
10
#include <sys/ioctl.h>
11
#include <sys/types.h>
12
#include <sys/socket.h>
14
#include <emscripten.h>
17
void main_loop(void *arg) {
21
struct sockaddr_in addr;
26
serverfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
28
perror("cannot create socket");
31
fcntl(serverfd, F_SETFL, O_NONBLOCK);
33
// bind to the supplied port
34
memset(&addr, 0, sizeof(addr));
35
addr.sin_family = AF_INET;
36
addr.sin_port = htons(SOCKK);
37
if (inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr) != 1) {
38
perror("inet_pton failed");
42
res = bind(serverfd, (struct sockaddr *)&addr, sizeof(addr));
44
perror("bind failed");
51
emscripten_set_main_loop(main_loop, 60, 0);
53
while (1) main_loop(NULL); sleep(1);