CodePudding user response:
Again carefully study the bind?CodePudding user response:
Can bind
Struct hostent * ht=gethostbyname (NULL);
for(int n=0; Ht & amp; & Ht - & gt; H_addr_list [n]. N++)
{
The SOCKET s=SOCKET (AF_INET, SOCK_STREAM, 0);
Sockaddr_in addr={0};
Addr. Sin_family=ht - & gt; H_addrtype;
//Addresses are returned in network byte order.
Addr. Sin_addr. S_addr=* (u_long *) ht - & gt; H_addr_list [n].
//service provider assigns a unique port
Addr. Sin_port=htons (0);
If (bind (s, (sockaddr *) & amp; Addr, sizeof (addr))==SOCKET_ERROR)
{
DWORD dwErr=WSAGetLastError ();
ASSERT (0);
}
//connect
{//while (1) the send recv}
Closesocket (s);
}