diff options
author | Oskar <[email protected]> | 2024-06-02 16:09:00 +0200 |
---|---|---|
committer | Oskar <[email protected]> | 2024-06-02 16:09:00 +0200 |
commit | cc2deeaefb53f5a40122f6cda31168021abcd139 (patch) | |
tree | 774b9b886c97692ec93cda000aa36f46bd346d14 | |
parent | 8b80185d9db97a5e8e93f763a4c190183317f44f (diff) |
client
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | client.c | 33 |
2 files changed, 28 insertions, 7 deletions
@@ -1,6 +1,6 @@ CC=gcc CFLAGS_TESTBIN=-Og -fsanitize=address -Wfatal-errors -Wall -Werror -Werror=return-type -Wextra -g -Wpedantic -std=gnu99 -CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -s -std=gnu99 +CFLAGS=-O3 -flto -march=native -DNDEBUG -fomit-frame-pointer -std=gnu99 MAKEFLAGS += -j$(nproc) TARGETS=helloworld TARGETS2=binding @@ -15,6 +15,30 @@ #define __FAIL EXIT_FAILURE #define BACKLOG 2 #define __PORT "62000" +#define BUF_SZ_2 2048 + +int talk_to_server (int sockfd) { + + while (1) { + char editbuffer[BUF_SZ_2]; + fprintf(stdout, ": "); + + char *fgs = fgets(editbuffer, BUF_SZ_2, stdin); + socklen_t fgs_len = strlen(editbuffer); + if (fgs == NULL) { + return 0; + } + + if (editbuffer[0] == '\n') { + send(sockfd, editbuffer, fgs_len, 0); + continue; + } else { + send(sockfd, editbuffer, fgs_len, 0); + continue; + } + } + return 0; +} int main () { @@ -55,13 +79,10 @@ int main () { } - char *msg = "Client says hello!\n"; - size_t len = strlen(msg); + //char *msg = "Client says hello!\n"; + //size_t len = strlen(msg); - for (int i = 0 ; i < 10 ; i++) { - - send(sockfd, msg, len, 0); - } + talk_to_server(sockfd); freeaddrinfo(res); return 0; } |