Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

*another* basic Winsock Problem.

Status
Not open for further replies.

Sebastiani

Programmer
Nov 3, 2002
38
US
Hi, all. Now that I have the client functioning, I would like to complete the server. The problem I am having now is with bind()ing the listening socket. Here is the code I am using:

Code:
bool bind(SOCKET sock, unsigned long address, unsigned short port = 80)
{
 sockaddr_in local;
 memset(&local, 0, sizeof(sockaddr_in));
 local.sin_family = AF_INET;
 local.sin_port = port;//...also tried htons(port)...
 local.sin_addr.S_un.S_addr = address;
 return ::bind(sock, (sockaddr*)&remote, sizeof(remote)) != SOCKET_ERROR;
}

The two addresses I tried as the second parameter were the manifest constants INADDR_ANY and INADDR_LOOPBACK (as well as htonl(INADDR_ANY) and htonl(INADDR_LOOPBACK) ).

Any ideas?
 
Sorry about the typos. Corrected it should read:

Code:
bool bind(SOCKET sock, unsigned long address, unsigned short port = 80)
{
 sockaddr_in local;
 memset(&local, 0, sizeof(sockaddr_in));
 local.sin_family = AF_INET;
 local.sin_port = port;//...also tried htons(port)...
 local.sin_addr.S_un.S_addr = address;
 return ::bind(sock, (sockaddr*)&local, sizeof(local)) != SOCKET_ERROR;
}

 
O.K. Got it.

Code:
bool bind(SOCKET sock, unsigned long address, unsigned short port = 80)
{
 sockaddr_in local;
 memset(&local, 0, sizeof(local));
 local.sin_family = AF_INET;
 local.sin_port = htons(port);
 local.sin_addr.S_un.S_addr = htonl(address);
 return ::bind(sock, (sockaddr*)&local, sizeof(local)) != SOCKET_ERROR;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top