send test
This commit is contained in:
@@ -26,11 +26,13 @@ pthread_mutex_t sendmut, receivemut;
|
|||||||
int sockfd, confd;
|
int sockfd, confd;
|
||||||
|
|
||||||
void *input(void *arg) {
|
void *input(void *arg) {
|
||||||
char msg[30];
|
char *msg;
|
||||||
char *copy = malloc(31);
|
char *copy;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
msg = malloc(30);
|
||||||
printf("Type a message: ");
|
printf("Type a message: ");
|
||||||
fgets(msg, sizeof(msg), stdin);
|
fgets(msg, sizeof(msg), stdin);
|
||||||
|
copy = malloc(30);
|
||||||
strcpy(copy, msg);
|
strcpy(copy, msg);
|
||||||
pthread_mutex_lock(&sendmut);
|
pthread_mutex_lock(&sendmut);
|
||||||
ListAppend(sendlist, copy);
|
ListAppend(sendlist, copy);
|
||||||
@@ -40,12 +42,14 @@ void *input(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void *sender(void *arg) {
|
void *sender(void *arg) {
|
||||||
char msg[30];
|
char *msg;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
msg = malloc(30);
|
||||||
pthread_mutex_lock(&sendmut);
|
pthread_mutex_lock(&sendmut);
|
||||||
if (ListCount(sendlist) != 0) {
|
if (ListCount(sendlist) != 0) {
|
||||||
ListFirst(sendlist);
|
ListFirst(sendlist);
|
||||||
strcpy(msg, ListCurr(sendlist));
|
strcpy(msg, ListCurr(sendlist));
|
||||||
|
send(confd, &msg, 30, 0);
|
||||||
ListRemove(sendlist);
|
ListRemove(sendlist);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -106,6 +110,7 @@ int main(int argc, char* argv[]) {
|
|||||||
char *remote_machine, *local_port, *remote_port;
|
char *remote_machine, *local_port, *remote_port;
|
||||||
int status;
|
int status;
|
||||||
int yes = 1;
|
int yes = 1;
|
||||||
|
char buf[20];
|
||||||
|
|
||||||
if (argc != 4) {
|
if (argc != 4) {
|
||||||
printf("Wrong number of arguments. Usage: ./chatty <local port> \
|
printf("Wrong number of arguments. Usage: ./chatty <local port> \
|
||||||
@@ -185,6 +190,7 @@ int main(int argc, char* argv[]) {
|
|||||||
s,
|
s,
|
||||||
sizeof s);
|
sizeof s);
|
||||||
printf("Getting chatty with %s\n", s);
|
printf("Getting chatty with %s\n", s);
|
||||||
|
send(confd, "test", 4, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memset(&hints, 0, sizeof(hints));
|
memset(&hints, 0, sizeof(hints));
|
||||||
@@ -222,8 +228,10 @@ int main(int argc, char* argv[]) {
|
|||||||
else {
|
else {
|
||||||
servinfo = q;
|
servinfo = q;
|
||||||
}
|
}
|
||||||
printf("Connected!\n");
|
recv(sockfd, buf, 4, 0);
|
||||||
|
printf("%s\n", buf);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
pthread_create(&input_thread, NULL, input, NULL);
|
pthread_create(&input_thread, NULL, input, NULL);
|
||||||
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);
|
||||||
@@ -232,6 +240,8 @@ int main(int argc, char* argv[]) {
|
|||||||
pthread_join(send_thread, NULL);
|
pthread_join(send_thread, NULL);
|
||||||
pthread_join(receive_thread, NULL);
|
pthread_join(receive_thread, NULL);
|
||||||
pthread_join(output_thread, NULL);
|
pthread_join(output_thread, NULL);
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
close(confd);
|
close(confd);
|
||||||
|
|||||||
Reference in New Issue
Block a user