-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathclient.c
More file actions
37 lines (33 loc) · 795 Bytes
/
client.c
File metadata and controls
37 lines (33 loc) · 795 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
/*
Copyright (C) 2010 IsmAvatar <IsmAvatar@gmail.com>
This file is part of EnigmaNet
EnigmaNet is free software and comes with ABSOLUTELY NO WARRANTY.
See LICENSE for details.
*/
#include "net.h"
#define TCP
int main(int argc, char *argv[]) {
#ifdef TCP
int s = net_connect_tcp(NULL,"2334",0);
#else
int s = net_connect_udp("2334",0);
#endif
if (s < 0) {
printf("Failed to connect (%d)\n",s);
return 0;
}
printf("Connected to %d\nSending: %s\n",s,"Hello World");
int r;
char *msg = "Hello World";
if (r = net_send(s,msg,strlen(msg)+1) < 0) {
printf("Send error (%d, %d)\n",r,errno);
return 0;
}
char *str;
if ((str = net_receive(s)) == NULL)
printf("Receive error (%d)\n",errno);
else
printf("Received: %s\n",str);
closesocket(s);
printf("Session terminated\n");
}