0

I have a tcp server application on windows (c#) wich accepts any connection by the port 3000 I have a tcp client application on linux(ubuntu)(c++) wich send a simple text by the port 3000

I also have a client on windows and a server on linux, i works perfectly sending the text: from linux to linux from windows to windows from windows to linux

the problem is that when i try to send from linux client to windows server my c++ application on linux tells me that the host doesn't exist

i already check the ip adress and it is correct i also tried to do it with hostname

but it doesn't work

does anybody know why it happens???

this is my code on the client(linux-c++):

int sockfd, portno, n;
struct sockaddr_in serv_addr;
struct hostent *server;  
struct in_addr addr={0};
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");
addr.s_addr=inet_addr(argv[1]);
//server=gethostbyname(argv[1]);
server = gethostbyaddr((char *) &addr, 4, AF_INET);
if (server == NULL) {
    fprintf(stderr,"ERROR, no such host\n");
    exit(0);
}

i call ping and everything is ok

I run my server on windows and open port 3000 to any conection

I try to run my client(code above) with the windowsIP/windowsHostName and the port 3000(Already tried another port)

and the problem is in the line:

server = gethostbyaddr((char *) &addr, 4, AF_INET);

server gets null so it prints "ERROR, no such host"

but the ip is correct.

When i use the same code for conecting with a server on linux(c++) it works

  • what happens when you call nslookup or ping from the linux box using the windows host name? – Marlin Pierce May 08 '12 at 21:58
  • 1 .In Windows2Windows case, is current Windows server or client? 2. Has the (linux)client connected to server? 3. Please paste the error print. – wuliang May 08 '12 at 22:08
  • I already called ping on linux with the ip address of windows and viceversa and it works perfectly – Francisco Gutiérrez May 08 '12 at 22:10
  • yes, the linux client already connect with a sever but it was also in linux. And my client on windwso also connected with the server in linux, the only problem is when i used the server on windows, and the client on linux – Francisco Gutiérrez May 08 '12 at 22:39
  • Have you tried to telnet from the linux box to the Windows server? What was the result? What IP address is on the Windows server? Could the gateway used by the Linux box not know how to route to the Windows box? – Brad Bruce May 08 '12 at 23:29

2 Answers2

0

The most probable reason is that you have your Windows Firewall blocking incoming connections to port 3000.

Go to Control Panel and Disable your firewall and test it again. If this is the problem you'll have to add a rule to allow incoming connections to your 3000 port. You should also include in the rule the allowed host IP (your Linux IP) to avoid problems with unexpected remote connections.

You can try making a telnet connection form linux to your server IP Address and 3000 port. It will probably be rejected by the firewall.

JotaBe
  • 38,030
  • 8
  • 98
  • 117
0

You need to set the network type in Virtual box as "NAT". The above problem occurs if it is in bridged adapter. A detailed discussion can be found here: http://ubuntuforums.org/archive/index.php/t-1786307.html

smip
  • 1
  • 1
  • 1