Permalink
Browse files

started client, responses now sent from separate thread

  • Loading branch information...
Rod Howarth
Rod Howarth committed Oct 25, 2011
1 parent d33bc37 commit e1846f894015fea0010300e0f57f92d328bff66b
Showing with 275 additions and 87 deletions.
  1. BIN HttpServer
  2. +61 −0 client.c
  3. +214 −87 server.c
View
Binary file not shown.
View
@@ -0,0 +1,61 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <unistd.h>
+
+#define BUFFER_SIZE 1024
+
+
+int main(int argc, char *argv[])
+{
+ int sockfd, numbytes, server_port;
+ char buffer[MAX_DATA_SIZE];
+ struct hostent *he;
+ struct sockaddr_in their_addr;
+
+ if (argc != 3) {
+ fprintf(stderr,"Please supply hostname and port\n");
+ exit(1);
+ }
+
+ //get the host by name
+ if ((he=gethostbyname(argv[1])) == NULL) {
+ herror("gethostbyname");
+ exit(1);
+ }
+
+ //read the port to conncet on
+ server_port = atoi(argv[1]);
+
+ if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+ perror("Failed to initialize socket");
+ exit(1);
+ }
+
+ their_addr.sin_family = AF_INET;
+ their_addr.sin_port = htons(server_port);
+ their_addr.sin_addr = *((struct in_addr *)he->h_addr);
+ bzero(&(their_addr.sin_zero), 8);
+
+ if (connect(sockfd, (struct sockaddr *)&their_addr, \
+ sizeof(struct sockaddr)) == -1) {
+ perror("Unable to connect");
+ exit(1);
+ }
+
+ if ((numbytes=recv(sockfd, buffer, MAXDATASIZE, 0)) == -1) {
+ perror("Unable to receive data");
+ exit(1);
+ }
+
+ buf[numbytes] = '\0';
+
+ printf("Response: %s",buffer);
+ close(sockfd);
+ return 0;
+}
Oops, something went wrong.

0 comments on commit e1846f8

Please sign in to comment.