1.1.0 release
This commit is contained in:
@@ -169,7 +169,8 @@ int main(void)
|
||||
}
|
||||
pthread_detach(thread);
|
||||
|
||||
printf("INFO: New client connected\n");
|
||||
printf("INFO: New client connected from %s:%d\n", client->addr.str,
|
||||
client->addr.port);
|
||||
}
|
||||
|
||||
sock_close(server);
|
||||
|
||||
32
examples/hello_client_v6.c
Normal file
32
examples/hello_client_v6.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define SOCK_IMPLEMENTATION
|
||||
#include "sock.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bool err = false;
|
||||
|
||||
Sock *sock = sock_create(SOCK_IPV6, SOCK_TCP);
|
||||
if (sock == NULL) { err = "create"; goto defer; }
|
||||
|
||||
SockAddr addr = sock_addr("::1", 6969);
|
||||
|
||||
if (!sock_connect(sock, addr)) { err = "connect"; goto defer; }
|
||||
|
||||
const char *msg = "Hello from client!";
|
||||
char buf[128];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
sock_send(sock, msg, strlen(msg));
|
||||
sock_recv(sock, buf, sizeof(buf));
|
||||
printf("%s:%d: %.*s\n", sock->addr.str, sock->addr.port,
|
||||
(int)sizeof(buf), buf);
|
||||
|
||||
defer:
|
||||
sock_close(sock);
|
||||
if (err) sock_log_errors();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
#define SOCK_IMPLEMENTATION
|
||||
#include "sock.h"
|
||||
|
||||
int main(void) {
|
||||
int main(void)
|
||||
{
|
||||
char *err = "None";
|
||||
|
||||
Sock *sock = sock_create(SOCK_IPV4, SOCK_TCP);
|
||||
|
||||
36
examples/hello_server_v6.c
Normal file
36
examples/hello_server_v6.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define SOCK_IMPLEMENTATION
|
||||
#include "sock.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
bool err = false;
|
||||
|
||||
Sock *sock = sock_create(SOCK_IPV6, SOCK_TCP);
|
||||
if (sock == NULL) { err = true; goto close; }
|
||||
|
||||
SockAddr addr = sock_addr("::", 6969);
|
||||
if (!sock_bind(sock, addr)) { err = true; goto close; }
|
||||
if (!sock_listen(sock, 16)) { err = true; goto close; }
|
||||
|
||||
Sock *client = sock_accept(sock);
|
||||
if (client == NULL) { err = true; goto close; }
|
||||
|
||||
const char *msg = "Hello from server!";
|
||||
char buf[128];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
|
||||
sock_send(client, msg, strlen(msg));
|
||||
sock_recv(client, buf, sizeof(buf));
|
||||
printf("%s:%d: %.*s\n", client->addr.str, client->addr.port,
|
||||
(int)sizeof(buf), buf);
|
||||
|
||||
sock_close(client);
|
||||
|
||||
close:
|
||||
sock_close(sock);
|
||||
if (err) sock_log_errors();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user