-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.cpp
More file actions
43 lines (28 loc) · 750 Bytes
/
client.cpp
File metadata and controls
43 lines (28 loc) · 750 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
#include <emscripten.h>
#include <emscripten/fetch.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
static const int PORT = 8080;
static const char* IP = "127.0.0.1";
int EMSCRIPTEN_KEEPALIVE main(int argc, char const *argv[])
{
struct sockaddr_in server;
int sock;
char buf[32];
int n;
sock = socket(AF_INET, SOCK_STREAM, 0);
server.sin_family = AF_INET;
server.sin_port = htons(PORT);
inet_pton(AF_INET, IP, &server.sin_addr.s_addr);
connect(sock, (struct sockaddr *)&server, sizeof(server));
memset(buf, 0, sizeof(buf));
n = read(sock, buf, sizeof(buf));
printf("%d, %s\n", n, buf);
close(sock);
return 0;
}