954,535 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help! Network programming in C++

I'm using windows sockets 2, and I've been able to write a server using a client array of sockets to hold more than 1 client at a time. All of this is fine and dandy, I can have multiple clients from the local machine connect to 127.0.0.1 without a problem.

However, when I try to use network IP addresses from within my network (which the router shouldn't bother?) I can't get a connection!

Normally when I'm using blocking mode before I connect, I get a good 10-20 second pause before my socket returns a failed connection if the server isn't running. However, when the server runs and I use a network IP, my socket fails almost immediately. Could this be due to the IP being valid, but the port being closed due to the router? I didn't think routers blocked ports for applications within the network, only to the outside internet.

I'm using gethostbyname() for a valid network address, so I know my IP is valid. I haven't been able to foward my port through my router to get it work either; I've run into a bit of a road block. Thanks for your help.

Mr Violent
Newbie Poster
22 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

When the connection fails, get the error number by using GetLastError(). Then lookup for it's description in MSDN or the winerror.h file. That will give you an idea on what is causing it.

WolfPack
Postaholic
Moderator
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
 

I found my problem. Apparently when you set the server's service IP to 127.0.0.1, it only accepts connections from that address. By setting it to INADDR_ANY it accepts any connection. Thanks for the help though!

Mr Violent
Newbie Poster
22 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You