Home > Back-end >  How Windows card, more socket specified network communication
How Windows card, more socket specified network communication

Time:01-19

C + + programming under the Windows, the computer has multiple network card, want to communicate at the same time in each nic network links, how to implement, to find the chian post, haven't found the available methods, bind not solve the problem,

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);
}



  • Related