I have one problem with Server/CLient Socket Programming model. On the same system meaning the same computer,I have a server running on one program and the client running another program. The Server/Client are talking thru address 0.0.0.0 and port 3000. The communication is fine.
However, when I have the Server program running one system and Client Program running on another system(two different computers and both of them are Wifi capable) Then Socket Programming model DO not work for my anymore.
Why is that?
portno=30000;
serv_addr.sin_family = AF_INET;
char *srvr_addr=NULL;
srvr_addr="0.0.0.0";
inet_addr(srvr_addr);
serv_addr.sin_addr.s_addr =inet_addr(srvr_addr);
serv_addr.sin_port = htons(portno);
bind(sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr));
listen(sockfd,5);
while (1)
{
clilen = sizeof(cli_addr);
newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen);
client side
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
portno=3000;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
server = gethostbyname("0.0.0.0");
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
//source, destination
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(30000);
serv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
int result;
result=connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr));
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
bzero(buffer,256);
n = read(sockfd,buffer,255);