looped client sending && TODOs

This commit is contained in:
Václav Šmejkal 2023-02-20 14:12:26 +01:00
parent faa63577ee
commit 368c57c285
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59
2 changed files with 14 additions and 4 deletions

View File

@ -23,19 +23,29 @@ void send_socket(char *text, int socket);
int main(void) int main(void)
{ {
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
char *line = NULL;
size_t line_length = 0;
//DEFINE SERVER ADDRESS //DEFINE SERVER ADDRESS
struct sockaddr_in server_addr; struct sockaddr_in server_addr;
server_addr.sin_family = AF_INET; server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(SERVER_PORT); server_addr.sin_port = htons(SERVER_PORT);
server_addr.sin_addr.s_addr = INADDR_ANY;
int connectStatus = connect(listen_socket, (SA *) &server_addr, sizeof(server_addr)); //CONNECT int connectStatus = connect(listen_socket, (SA *) &server_addr, sizeof(server_addr)); //CONNECT
if (connectStatus < 0) why2_die("Connecting failed."); if (connectStatus < 0) why2_die("Connecting failed.");
send_socket("123456789123456789", listen_socket); for (;;)
{
printf(">>> ");
getline(&line, &line_length, stdin);
printf("%s\n", line);
send_socket(line, listen_socket);
}
free(line); //TODO: Unreachable; add exit
return 0; return 0;
} }

View File

@ -43,11 +43,11 @@ int main(void)
//LOOP ACCEPT //LOOP ACCEPT
for (;;) for (;;)
{ {
accepted = accept(listen_socket, (SA *) NULL, NULL); //ACCEPT NEW SOCKET //TODO: CLOSE accepted = accept(listen_socket, (SA *) NULL, NULL); //ACCEPT NEW SOCKET //TODO: CLOSE (not only this one)
if (accepted == -1) why2_die("Accepting socket failed!"); if (accepted == -1) why2_die("Accepting socket failed!");
received = read_socket(accepted); received = read_socket(accepted); //TODO: Add multithreading
if (received == NULL) continue; //FAILED if (received == NULL) continue; //FAILED