Hello all.

I've completed both a Winsock server, AND a Winsock client using C++. The problem comes in when I attempt to bind a socket to a remote IP address. I get the message "Unable to bind to "IP address" port 80.

I know for a fact that both the port, and protocol type are correct; however, what I don't know is why I am unable to "bind" to a remote IP address.

(Note: The IP address belongs to a dedicated server I have recently bought).

What troubles me is that winsock never asks me to input a username, or password to be able to "bind" a socket to a server IP address. Perhaps there is a winsock function that I am missing that requires me to input a username and a password before I am able to "bind" a socket to an IP address?

Thank you in advance.

I think you're being confused about what bind actually does.

Bind says "This is the application that wants to start listening on this port at this IP Address. Please forward anything that comes there to me. Also, please don't let anyone else use this IP/Port combination. Thanks o/" and effectively reserves that port for your application.

The bind is done in your server application before you start listening. You client connects to that port using the Connect command.

There are some rules to being able to bind:
1. The port must not be bound (in-use) by any other application.
2. The port must be between 1 and 65535
3. There are reserved ports below 1024. It's a good idea to use ports above this number.
4. The IP Address must belong to the system where you are binding. Valid bindings are 0.0.0.0 (all IP Addresses), 127.0.0.1 (local loopback) and your network card address.

For example: My local IP Address is 192.168.0.244 and Daniweb's IP Address is 74.53.219.188.

I can bind to 0.0.0.0, 127.0.0.1 and 192.168.0.244. I *cannot* bind to 74.53.219.188 because that IP Address is not on my system.

Binding to an IP/Port does not require a password unless your operating system has a security option forcing it, at which point the user of the application must input it, not the application itself.

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.