added basic input thread function
This commit is contained in:
@@ -22,6 +22,7 @@
|
|||||||
#define BACKLOG 10
|
#define BACKLOG 10
|
||||||
|
|
||||||
LIST *receivelist, *sendlist;
|
LIST *receivelist, *sendlist;
|
||||||
|
pthread_mutex_t sendmut, receivemut;
|
||||||
|
|
||||||
void *input(void *arg) {
|
void *input(void *arg) {
|
||||||
char msg[512];
|
char msg[512];
|
||||||
@@ -29,7 +30,9 @@ void *input(void *arg) {
|
|||||||
while (1) {
|
while (1) {
|
||||||
printf("Type a message: ");
|
printf("Type a message: ");
|
||||||
scanf("%s", msg);
|
scanf("%s", msg);
|
||||||
printf("%s", msg);
|
pthread_mutex_lock(&sendmut);
|
||||||
|
ListAppend(sendlist, msg);
|
||||||
|
pthread_mutex_unlock(&sendmut);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -52,7 +55,7 @@ void *get_in_addr(struct sockaddr *sa) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
pthread_t input_thread, send_thread, receive_thread;
|
pthread_t input_thread, send_thread, receive_thread, output_thread;
|
||||||
socklen_t sin_size;
|
socklen_t sin_size;
|
||||||
struct addrinfo *p, *q;
|
struct addrinfo *p, *q;
|
||||||
struct addrinfo hints;
|
struct addrinfo hints;
|
||||||
@@ -66,11 +69,14 @@ int main(int argc, char* argv[]) {
|
|||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
local_port = argv[1];
|
pthread_mutex_init(&sendmut, NULL);
|
||||||
|
pthread_mutex_init(&receivemut, NULL);
|
||||||
|
|
||||||
|
local_port = argv[1];
|
||||||
remote_machine = argv[2];
|
remote_machine = argv[2];
|
||||||
remote_port = argv[3];
|
remote_port = argv[3];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user