Commit 3a45f2c7 authored by cdf009's avatar cdf009

Lab4 push

parent 0652778f
......@@ -28,6 +28,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "wrappers.c"
#define BUFFER_SIZE 512 // length of message buffer
#define QLEN 6 // length of request queue
......@@ -63,7 +64,9 @@ main (int argc, char* argv[]) {
int sd, sd2; // socket descriptors
int port; // protocol port number
socklen_t alen; // length of address
char in_msg[BUFFER_SIZE]; // buffer for incoming message
char in_msg[BUFFER_SIZE];
char read_msg1[BUFFER_SIZE];
// buffer for incoming message
// prepare address data structure
......@@ -129,15 +132,25 @@ main (int argc, char* argv[]) {
num_requests++;
// receive the string sent by client
strcpy(in_msg, "");
recv(sd2, &in_msg, BUFFER_SIZE, 0);
printf("done");
// send the received string back to client
//send(sd, buf, len flags);
send(sd2, &in_msg, BUFFER_SIZE, 0);
close(sd2);
//char write_msg[BUFFER_SIZE];
recv(sd2,&in_msg, BUFFER_SIZE, 0);
printf("done");
printf("Received:%s\n", in_msg);
// Read(parent_to_child[READ_END], &read_msg, BUFFER_SIZE);i
strcpy(read_msg1, "");
char* str1 = " ";
char* str2 = strtok(in_msg, str1);
while(str2!= NULL){
printf("Words in String:%s\n", str2);
strcat(read_msg1, str1);
strcat(read_msg1, str2);
str2 = strtok(NULL, str1);
}
send(sd2, &read_msg1, BUFFER_SIZE, 0);
Close(sd2);
}
}
......@@ -27,6 +27,7 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "wrappers.c"
#define BUFFER_SIZE 512
#define TRUE 1
......@@ -107,13 +108,15 @@ main(int argc, char* argv[]) {
}
// send message to server
send(sd, &in_msg, BUFFER_SIZE, 0);
char write_msg[BUFFER_SIZE];
strcpy(write_msg, argv[3]);
send(sd, &write_msg, BUFFER_SIZE, 0);
printf("sent");
// send the received string back to client
printf("\n");
// //send(sd, buf, len flags);
strcpy(in_msg, "");
recv(sd, &in_msg, BUFFER_SIZE, 0);
recv(sd, in_msg, BUFFER_SIZE, 0);
//
// receive message echoed back by server
......@@ -121,7 +124,7 @@ main(int argc, char* argv[]) {
printf("ECHOREQ: from server= %s\n", in_msg);
// close the socket
close(sd);
Close(sd);
// terminate the client program gracefully
return(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment