From 8b80185d9db97a5e8e93f763a4c190183317f44f Mon Sep 17 00:00:00 2001 From: Oskar Date: Sun, 2 Jun 2024 15:33:57 +0200 Subject: made new file for dumb client, because i will make a slightly smarter one that doesnt just send a message and exit --- dumbclient.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 dumbclient.c (limited to 'dumbclient.c') diff --git a/dumbclient.c b/dumbclient.c new file mode 100644 index 0000000..e023465 --- /dev/null +++ b/dumbclient.c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// int listen(int sockfd, int backlog); +#define __FAIL EXIT_FAILURE +#define BACKLOG 2 +#define __PORT "62000" + +int main () { + + int sockfd = -1; + int gai_result; + int connect_result = -1; + struct addrinfo hints; + struct addrinfo *res; + struct addrinfo *p; + memset(&hints, 0, sizeof(hints)); + //hints.ai_flags = ; + hints.ai_family = AF_INET; + hints.ai_socktype = SOCK_STREAM; + + gai_result = getaddrinfo("192.168.1.18", __PORT, &hints, &res); + if (gai_result != 0) { + fprintf(stderr, "getaddrinfo: %d", gai_result); + exit(__FAIL); + } + + for (p = res ; p != NULL ; p = p->ai_next) { + + sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol); + if (sockfd == -1) { + fprintf(stderr, "socket fail\n"); + continue; + } + + connect_result = connect(sockfd, p->ai_addr, p->ai_addrlen); + if (connect_result == -1) { + fprintf(stderr, "connect fail\n"); + continue; + } + + } + if (connect_result == -1 || sockfd == -1) { + exit(__FAIL); + } + + + char *msg = "Client says hello!\n"; + size_t len = strlen(msg); + + for (int i = 0 ; i < 10 ; i++) { + + send(sockfd, msg, len, 0); + } + freeaddrinfo(res); + return 0; +} -- cgit v1.2.3