added chat log that shows both sides' messages

This commit is contained in:
2025-08-06 19:37:20 -06:00
parent c20d20fa7e
commit 4fff0db858
+9 -3
View File
@@ -27,7 +27,8 @@ pthread_mutex_t sendmut, receivemut;
int sockfd, confd, client; int sockfd, confd, client;
char *remote_machine, *local_port, *remote_port; char *remote_machine, *local_port, *remote_port;
int row, col; int row, col;
char s[INET6_ADDRSTRLEN]; char s[INET6_ADDRSTRLEN];
char closed[] = "Connection closed.";
/* /*
void *input(void *arg) { void *input(void *arg) {
@@ -66,14 +67,18 @@ void *sender(void *arg) {
char error[] = "pthread sender exit"; char error[] = "pthread sender exit";
while (1) { while (1) {
pthread_mutex_unlock(&sendmut);
memset(msg, 0, 128); memset(msg, 0, 128);
mvprintw(row - 1, 0, "Type a message: "); mvprintw(row - 1, 0, "Type a message: ");
getstr(msg); getstr(msg);
refresh();
bytes = send(confd, msg, sizeof(msg), 0); bytes = send(confd, msg, sizeof(msg), 0);
move(0, 0);
deleteln();
move(row - 2, 0);
deleteln();
mvprintw(row - 2, 0, "You: %s", msg);
move(row - 1, 0); move(row - 1, 0);
clrtoeol(); clrtoeol();
refresh();
if (bytes == -1) { if (bytes == -1) {
perror("send"); perror("send");
pthread_exit(&error); pthread_exit(&error);
@@ -89,6 +94,7 @@ void *receiver(void *arg) {
while (1) { while (1) {
memset(buf, 0, 128); memset(buf, 0, 128);
bytes = recv(confd, buf, 128, 0); bytes = recv(confd, buf, 128, 0);
if (bytes != -1) { if (bytes != -1) {
move(0, 0); move(0, 0);
deleteln(); deleteln();