Skip to content

Commit

Permalink
Makefile e thread
Browse files Browse the repository at this point in the history
  • Loading branch information
NdA994 committed Mar 28, 2020
1 parent c8ac9f3 commit 509031e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ LIBS=-pthread
all: server.out

server.out:
$(CC) $(CFLAGS) $(LIBS) -o server.out server.o

client.out:
$(CC) $(CFLAGS) $(LIBS) -o client.out client.o string.o
gcc -o server.out server.c -pthread

clean:
rm *.o *.out
rm *.out
25 changes: 15 additions & 10 deletions server.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@ struct ClientNode {

int count;
struct ClientNode list[10];
int server_fd, new_socket, valread;
char buffer[1024] = {0};
char *hello = "Hello from server";


void client_handler() {
printf("thread");
while(1){
valread = read( new_socket, buffer, 1024);
printf("%s\n",buffer);
send(new_socket, hello, strlen(hello), 0);
printf("Hello message sent\n");
close(new_socket);
}

}

int main(int argc, char const *argv[]) {
int server_fd, new_socket, valread;

struct sockaddr_in address;
int opt = 1;
int addrlen = sizeof(address);
char buffer[1024] = {0};
char *hello = "Hello from server";


// Creating socket file descriptor
if ((server_fd = socket(AF_INET, SOCK_STREAM, 0)) == 0) {
perror("socket failed");
Expand Down Expand Up @@ -68,11 +77,7 @@ int main(int argc, char const *argv[]) {
exit(EXIT_FAILURE);
}

valread = read( new_socket, buffer, 1024);
printf("%s\n",buffer);
send(new_socket, hello, strlen(hello), 0);
printf("Hello message sent\n");
close(new_socket);

}
return 0;
}

0 comments on commit 509031e

Please sign in to comment.