simworld/client/src/main.c

35 lines
614 B
C
Raw Normal View History

2024-10-04 05:05:43 +00:00
// main.c
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include "error.h"
#include "sock.h"
2024-10-04 05:05:43 +00:00
int main(void) {
enum error_t err = ERR_OK;
int sock;
err = sock_init(&sock);
if (err) goto handle_error;
char ibuf[1028] = { 0 };
char obuf[1028] = { 0 };
strcpy(obuf, "Hello, world!\n");
// Just echoing everything back for now
write(sock, obuf, 1028);
int rc = read(sock, ibuf, 1028);
if (rc > 0) printf("%s", ibuf);
close(sock);
return ERR_OK;
2024-10-04 05:05:43 +00:00
handle_error:
printf("ERROR: %s\n", ERROR_STRS[err]);
return err;
2024-10-04 05:05:43 +00:00
}