-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.cpp
More file actions
46 lines (31 loc) · 793 Bytes
/
server.cpp
File metadata and controls
46 lines (31 loc) · 793 Bytes
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
46
#include <emscripten.h>
#include <emscripten/fetch.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
static const int PORT = 8080;
int EMSCRIPTEN_KEEPALIVE main(int argc, char const *argv[])
{
int sock0;
struct sockaddr_in addr;
struct sockaddr_in client;
int len;
int sock;
sock0 = socket(AF_INET, SOCK_STREAM, 0);
addr.sin_family = AF_INET;
addr.sin_port = htons(PORT);
addr.sin_addr.s_addr = INADDR_ANY;
bind(sock0, (struct sockaddr *)&addr, sizeof(addr));
listen(sock0, 5);
while(true) {
printf("Waiting... \n");
sock = accept(sock0, (struct sockaddr *)&client, (socklen_t *)sizeof(client));
write(sock, "HELLO", 5);
printf("Accepted \n");
}
close(sock);
close(sock0);
return 0;
}