added chat history
This commit is contained in:
@@ -27,12 +27,13 @@ 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;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void *input(void *arg) {
|
void *input(void *arg) {
|
||||||
char msg[128];
|
char msg[128];
|
||||||
while (1) {
|
while (1) {
|
||||||
memset(msg, 0, 128);
|
memset(msg, 0, 128);
|
||||||
printf("Type a message: ");
|
printf("Typpe a message: ");
|
||||||
fgets(msg, sizeof(msg), stdin);
|
fgets(msg, sizeof(msg), stdin);
|
||||||
pthread_mutex_lock(&sendmut);
|
pthread_mutex_lock(&sendmut);
|
||||||
ListAppend(sendlist, msg);
|
ListAppend(sendlist, msg);
|
||||||
@@ -56,8 +57,6 @@ void *output(void *arg) {
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void *sender(void *arg) {
|
void *sender(void *arg) {
|
||||||
@@ -68,10 +67,12 @@ void *sender(void *arg) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
pthread_mutex_unlock(&sendmut);
|
pthread_mutex_unlock(&sendmut);
|
||||||
memset(msg, 0, 128);
|
memset(msg, 0, 128);
|
||||||
mvprintw(row - 2, 0, "Type a message: ");
|
mvprintw(row - 1, 0, "Type a message: ");
|
||||||
refresh();
|
|
||||||
getstr(msg);
|
getstr(msg);
|
||||||
|
refresh();
|
||||||
bytes = send(confd, msg, sizeof(msg), 0);
|
bytes = send(confd, msg, sizeof(msg), 0);
|
||||||
|
move(row - 1, 0);
|
||||||
|
clrtoeol();
|
||||||
if (bytes == -1) {
|
if (bytes == -1) {
|
||||||
perror("send");
|
perror("send");
|
||||||
pthread_exit(&error);
|
pthread_exit(&error);
|
||||||
@@ -87,9 +88,12 @@ 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) {
|
||||||
mvprintw(row - 3, 10, ("Message: %s", buf));
|
move(0, 0);
|
||||||
|
deleteln();
|
||||||
|
refresh();
|
||||||
|
mvprintw(row - 2, 0, "Message: %s", buf);
|
||||||
|
move(row - 1, 16);
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
else if (bytes == 0) {
|
else if (bytes == 0) {
|
||||||
@@ -241,8 +245,10 @@ int main(int argc, char* argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initscr();
|
initscr();
|
||||||
|
cbreak();
|
||||||
getmaxyx(stdscr, row, col);
|
getmaxyx(stdscr, row, col);
|
||||||
pthread_create(&send_thread, NULL, sender, NULL);
|
keypad(stdscr, TRUE);
|
||||||
|
pthread_create(&send_thread, NULL, sender, NULL);
|
||||||
pthread_create(&receive_thread, NULL, receiver, NULL);
|
pthread_create(&receive_thread, NULL, receiver, NULL);
|
||||||
|
|
||||||
pthread_join(send_thread, NULL);
|
pthread_join(send_thread, NULL);
|
||||||
|
|||||||
Reference in New Issue
Block a user