1.1.0 release
This commit is contained in:
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;
|
||||
}
|
||||
Reference in New Issue
Block a user