views:

59

answers:

2

I have followed a tutorial on http://www.codeproject.com/KB/IP/beginningtcp_cpp.aspxt

which teaches how to use winsockets with c++, i finally managed to get my program to work, by testing wiht 127.0.0.1, i can open two process instances of my program and then make one listen on port (700) and then connect to it with the other program on port 700 with ip 127.0.0.1, i can then send messages between the two programs with no problems.

I sent the program to my friend, got his ip and told him to start listening on port 700, then i tried to connect to his ip address and port 700, the program froze for about 20 seconds (because i have it on the same thread as my window) and the connect() function returns SOCKET_ERROR here:

if (connect(g_sock, (SOCKADDR*)&target, sizeof(target)) == SOCKET_ERROR)
{
    return 4;
}

I have tried other ports and i have allowed it on windows firewall.. disabled window firewall too, disabled avast.

my code is almost the same as the one in the tutorial, and i have also downloaded the one in the tutorial and i get the same erro as mine.

I am using windows 7 ultimate 32 bit

A: 

Is either one of you behind a NAT firewall/router? The IP address you present to the outside world might not be the one that your own computer uses, which would make it impossible for the program to communicate with you unless you had some sort of tunnel set up through the NAT.

Paul Tomblin
A: 

Are you trying this across the Internet? There could be a firewall somewhere between both computers.

Ideally, you should test your program on a Local Area Network first. That's a more appropriate environment for this kind of test.

karlphillip