I have coded a server program which interacts with my client, but it doesnt interact with a browser, what could be the problem?
here is the
server.c:
Code:
#include <netinet/in.h>
#include <arpa/inet.h>
main(int argc, char *argv[])
{
int sockfd, newsockfd ; /* Socket descriptors */
int clilen;
struct sockaddr_in cli_addr, serv_addr;
int port;
int i, readsocks;
char buf[100]; /* We will use this buffer for communication */
if(argc != 2) {
printf("\nEnter port number only in the command line argument\n");
exit(0);
}
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
printf("Cannot create socket\n");
exit(0);
}
port = atoi(argv[1]);
printf("\nport is %d\n", port);
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = port;
if (bind(sockfd, (struct sockaddr *) &serv_addr,
sizeof(serv_addr)) < 0) {
printf("Unable to bind local address\n");
exit(0);
}
listen(sockfd, 5);
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr,
&clilen);
printf("wow Some client is connected\n\n");
close(newsockfd);
}
I am using "http://127.0.0.1:8080/" in the address bar of the mozilla firefox.
am running the server program on the same machine on the port 8080.
actually the server should print:
Code:
wow Some client is connected
but it does nothing..