got two way communication

This commit is contained in:
2025-07-28 00:48:22 -06:00
parent d297356eb3
commit 207c7a2919
-16
View File
@@ -60,25 +60,11 @@ void *output(void *arg) {
void *sender(void *arg) {
char msg[128];
if (client) {
while (1) {
pthread_mutex_lock(&sendmut);
memset(msg, 0, 128);
printf("Type a message: ");
fgets(msg, sizeof(msg), stdin);
send(newfd, msg, sizeof(msg), 0);
pthread_mutex_unlock(&sendmut);
}
}
else {
while (1) {
pthread_mutex_lock(&sendmut);
memset(msg, 0, 128);
printf("Type a message: ");
fgets(msg, sizeof(msg), stdin);
send(confd, msg, sizeof(msg), 0);
pthread_mutex_unlock(&sendmut);
}
}
return 0;
}
@@ -87,10 +73,8 @@ void *receiver(void *arg) {
char buf[128];
int bytes;
while (1) {
pthread_mutex_lock(&receivemut);
memset(buf, 0, 128);
bytes = recv(confd, buf, 128, 0);
pthread_mutex_unlock(&receivemut);
if (bytes != -1) {
printf("Received: %s\n", buf);