LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-01-2009, 01:14 AM   #1
vijaya_svk
Member
 
Registered: Nov 2007
Posts: 61

Rep: Reputation: 15
Problem with the Networking API


Hi
I am writing a client-server application in which i am having the following problem.

server.c
# include <unistd.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <string.h>
# include <netinet/in.h>
# include <stdio.h>
# include <stdlib.h>
# include <arpa/inet.h>
main()
{
int listfd,connfd,retval;
//pid_t childpid;
socklen_t clilen;
struct sockaddr_in cliaddr, servaddr;

listfd = socket(AF_INET, SOCK_STREAM, 0);
if (listfd < 0)
{
perror("sock:");
exit(1);
}
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(8000);

retval = bind(listfd, (struct sockaddr *) &servaddr, sizeof(servaddr));
if(retval < 0)
{
perror("bind:");
exit(2);
}

listen(listfd, 5);

while(1)
{
clilen = sizeof(cliaddr);
connfd = accept(listfd, (struct sockaddr *) &cliaddr, &clilen);
printf(" client connected \n");
printf(" client's port no = %d\n",htons(cliaddr.sin_port));
}
}


client.c

# include <unistd.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <string.h>
#include <netinet/in.h>
#include<stdio.h>
#include<stdlib.h>

int main()
{
char *serv_ip = "192.168.5.46";
int sockfd,ret_val;
struct sockaddr_in servaddr;
sockfd = socket(AF_INET, SOCK_STREAM, 0);

bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(8000);
inet_pton(AF_INET, serv_ip, &servaddr.sin_addr);

ret_val = connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));

if(ret_val <0 )
{
perror("connect:");
exit(1);
}
printf(" client established connection with server\n");
}


My server PC has the IP Address 192.168.5.46

when i execute the code with server IP as 127.0.0.1, and server and client on same PC it works fine

but when i execute the same application with server on 192.168.5.46 and client on 192.168.5.21. It doesnot work


The error is

connect:: No route to host


What would be the problem.........

Thank you in advance
 
Old 08-01-2009, 12:49 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
The problem is almost certainly in your network configuration (and not your program).

For starters: make sure that host 192.168.5.46 can "ping" 192.168.5.21; and 192.168.5.21 can "ping" 192.168.5.46.
 
Old 08-02-2009, 01:18 PM   #3
vijaya_svk
Member
 
Registered: Nov 2007
Posts: 61

Original Poster
Rep: Reputation: 15
Please help

Quote:
Originally Posted by paulsm4 View Post
The problem is almost certainly in your network configuration (and not your program).

For starters: make sure that host 192.168.5.46 can "ping" 192.168.5.21; and 192.168.5.21 can "ping" 192.168.5.46.
Sir
The two PC's were connected properly and pinging from bothsides. There is no problem with the network. Infact i am executing the program on the server with the client pc on an ssh console. When i am able to do ssh and execute the code, there must be no problem in the network.

Are you sure that the code is correct???
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with libtar api and large files SirSeoman Programming 1 01-04-2009 07:14 AM
LXer: An open API for networking technology? LXer Syndicated Linux News 0 02-20-2007 09:01 PM
MySQL C API problem anroy Programming 6 12-07-2006 08:23 PM
DB2 vendor API problem shitij Linux - Software 0 08-22-2004 05:23 PM
python DB-API for MySQL install problem SheldonPlankton Programming 1 07-27-2004 05:55 PM


All times are GMT -5. The time now is 03:25 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration