got two way communication

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