0
votes

Hi I am implementing P2P chatting application where server will mediator for exchangeing IP and port to connecting peer. I am getting WSAEAFNOSUPPORT 10047 error .

I have created UDP socket

sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP ); then iam binding it to local ip and port.

if (bind(sockfd,(struct sockaddr *)&localaddr,sizeof(localaddr))<0) { Error_Code("create_socket:bind()"); return -1; }

then I am contacting the server.

// connecting with server

sendto(sockfd,pBuffer,sizeof (nMessageType),0,(const sockaddr *)&config.serverAddr,size);

server keeps track of the other connected peer.once peer connects to the server it return ip and port of other peer.so a peer can use IP and port to directly connect to other peer. but i am getting error while sending data to to other peer

// sending data to peer

int ret = sendto(sockfd,sendBuf, sizeof(nMessagetype),0,(const sockaddr *)&m_peer.publicaddr,sockAddLen); it return 10047 WSAEAFNOSUPPORT error.

Here I am using same socket to contact server and other peer is this reason for this? I don't understand what is going wrong here. It is able to connect with server properly but it is failing to connect other peer.

1
Did you solve it? Did you get around to check that the two families are the same?Default

1 Answers

1
votes

Pointed out in the sendto and for the actual error message WSAEAFNOSUPPORT the address you are using to send to is not of the same family as the socket you are sending on.

You have to make sure that the address in m_peer.publicaddr is of the same family as sockfd. For instance, if you send an address for IPv6, AF_INET will not work (it would have to be AF_INET6)