Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi!!! I do socket programming. I have two programs.
client.c and server.c..
I have run server.c on one machine which has ip address 10.1.3.6 and client.c on another machine with ip address 10.1.3.14...
Both are on the same network.
I can ping to each other.
Bt when I tried to connect client and server I got the following error.
[root@pgcse14 ]# gcc client.c
[root@pgcse14 ]# ./a.out 10.1.3.6 6061
ERROR connecting: No route to host
Hi!!! I do socket programming. I have two programs.
client.c and server.c..
I have run server.c on one machine which has ip address 10.1.3.6 and client.c on another machine with ip address 10.1.3.14...
Both are on the same network. I can ping to each other.
Bt when I tried to connect client and server I got the following error.
[root@pgcse14 ]# gcc client.c
[root@pgcse14 ]# ./a.out 10.1.3.6 6061
ERROR connecting: No route to host
Please can anyone give me the solution...???
If the machines can ping each other, then they're on the network, up and working fine. So either you've got bugs in your software (which we can't help with, since you didn't post it), or you've got a firewall enabled, and it's blocking the ports.
Do you have selinux or any firewall(s) running on the boxes? Are these 'real' systems, or are they virtual machines?
Both PCs are real machines. And firewall is also disabled. Though m getting the same error. What should i do now????
Spell out your words.
And as I said in my first reply, if you don't have a firewall or any other type of barrier, then you've got a bug in your code. So, debug it. You don't post your code, so we can't help, but if you can communicate between both machines now, EXCEPT with your code, then the problem is in your code.
int main(int argc, char *argv[])
{
int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;
char buffer[256];
if (argc < 3) {
fprintf(stderr,"usage %s hostname port\n", argv[0]);
exit(0);
}
portno = atoi(argv[2]);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0)
error("ERROR opening socket");
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr,"ERROR, no such host\n");
exit(0);
}
bzero((char *) &serv_addr, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
bcopy((char *)server->h_addr,
(char *)&serv_addr.sin_addr.s_addr,
server->h_length);
serv_addr.sin_port = htons(portno);
printf("sockfd is %d :",sockfd);
if (connect(sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
error("ERROR connecting");
printf("Please enter the message: ");
bzero(buffer,256);
fgets(buffer,255,stdin);
n = write(sockfd,buffer,strlen(buffer));
if (n < 0)
error("ERROR writing to socket");
bzero(buffer,256);
n = read(sockfd,buffer,255);
if (n < 0)
error("ERROR reading from socket");
printf("%s\n",buffer);
close(sockfd);
return 0;
}
This is my program.... I have debugged this code. and it did not generate any error.
Ok....but because the code didn't generate an error at compile time, does not mean there aren't any problems in it. The STRUCTURE/FUNCTIONS of the program may not work.
Also, you have a client and a SERVER piece of software, right?? You need to examine both of them. Again, since networking services are working between both servers, this problem isn't in the Linux side of things, but in YOUR SOFTWARE. Put some tests into your software, some logging, something to tell you what's happening, where, and when. Do it on BOTH sides, and see what you're getting, and fix it from there.
Okay you are right. But when I run same program client.c and server.c on the single machine(not on different machines) both client and server connect each other successfully. And I got the true output.
But problem generates only when I run them on different machines(PCs)....
Okay you are right. But when I run same program client.c and server.c on the single machine(not on different machines) both client and server connect each other successfully. And I got the true output.
But problem generates only when I run them on different machines(PCs)....
A single machine will probably use the loopback address, and the network packets will not even leave your system...so yes, it's probably likely the program will run on a single machine.
Regardless...YOUR program doesn't work for its intended purpose. Linux has nothing to do with this, providing you've ensured there are no firewalls/iptables kinds of rules in place, and that you are SURE that the routers/switches in between the two aren't doing any sort of filtering/blocking on their own.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.