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.

Recommended Answers

All 2 Replies

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.

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.