bug fixes and made messages display sender

This commit is contained in:
2025-08-06 13:30:23 -06:00
parent 3552cfc8ac
commit c20d20fa7e
+11 -9
View File
@@ -27,6 +27,7 @@ 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];
/* /*
void *input(void *arg) { void *input(void *arg) {
@@ -91,9 +92,10 @@ void *receiver(void *arg) {
if (bytes != -1) { if (bytes != -1) {
move(0, 0); move(0, 0);
deleteln(); deleteln();
refresh(); move(row - 2, 0);
mvprintw(row - 2, 0, "Message: %s", buf); deleteln();
move(row - 1, 16); mvprintw(row - 2, 0, "%s: %s", s, buf);
mvprintw(row - 1, 0, "Type a message: ");
refresh(); refresh();
} }
else if (bytes == 0) { else if (bytes == 0) {
@@ -123,21 +125,20 @@ int main(int argc, char* argv[]) {
struct addrinfo hints; struct addrinfo hints;
struct addrinfo *servinfo; struct addrinfo *servinfo;
struct sockaddr_storage their_addr; struct sockaddr_storage their_addr;
char s[INET6_ADDRSTRLEN];
int status; int status;
int yes = 1; int yes = 1;
if (argc != 4) {
if (argc != 4) {
printf("Wrong number of arguments. Usage: ./chatty <local port> \ printf("Wrong number of arguments. Usage: ./chatty <local port> \
<remote IP> <remote port>\n"); <remote IP> <remote port>\n");
return -1; return -1;
} }
if (pthread_mutex_init(&sendmut, NULL) != 0) { if (pthread_mutex_init(&sendmut, NULL) != 0) {
printf("Error: send mutex init failed\n"); fprintf(stderr, "Error: send mutex init failed\n");
return -1; return -1;
} }
if (pthread_mutex_init(&receivemut, NULL) != 0) { if (pthread_mutex_init(&receivemut, NULL) != 0) {
printf("Error: receive mutex init failed\n"); fprintf(stderr, "Error: receive mutex init failed\n");
return -1; return -1;
} }
@@ -243,11 +244,12 @@ int main(int argc, char* argv[]) {
servinfo = q; servinfo = q;
} }
initscr(); initscr();
cbreak(); cbreak();
getmaxyx(stdscr, row, col); getmaxyx(stdscr, row, col);
keypad(stdscr, TRUE); keypad(stdscr, TRUE);
pthread_create(&send_thread, NULL, sender, NULL); pthread_create(&send_thread, NULL, sender, NULL);
pthread_create(&receive_thread, NULL, receiver, NULL); pthread_create(&receive_thread, NULL, receiver, NULL);