got two way communication
This commit is contained in:
@@ -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) {
|
||||||
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);
|
memset(msg, 0, 128);
|
||||||
printf("Type a message: ");
|
printf("Type a message: ");
|
||||||
fgets(msg, sizeof(msg), stdin);
|
fgets(msg, sizeof(msg), stdin);
|
||||||
send(confd, msg, sizeof(msg), 0);
|
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user