struct sockaddr_in addrSenderOfVideo
struct sockaddr_in client_addr; // Client Internet address
char* buffer = new char[2];
int sizeOfBuffer=1050;
int clientfd;
char* bufferWithPacketData = new char[sizeOfBuffer];
extern int client_s; // Client socket
if (client_s < 0)
{
printf("*** ERROR - socket() failed \n");
}
//Client address.
client_addr.sin_family = AF_INET;
client_addr.sin_addr.s_addr = htonl(INADDR_ANY); // IP address to use
client_addr.sin_port = htons(portNumClient);
clientfd = bind(client_s,(const sockaddr*) &client_addr, sizeof(client_addr));
fprintf (stderr, "inside of listen for new packet<; clientfd is %d",clientfd);
if (clientfd < 0)
{
fprintf (stderr, "WARNING -1 doing BIND!");
}
int n = recvfrom (client_s, bufferWithPacketData, sizeOfBuffer, 0,(struct sockaddr*)&addrSenderOfVideo, &fromlen);
retcode = sendto(client_s, buffer, symbol_size, 0,
(struct sockaddr *)&addrSenderOfVideo, sizeof(addrSenderOfVideo) );
调用 sendto 时,会打印出错误“9errno is Bad address”。这是什么原因,我该如何解决?
数据在函数 recvfrom 中从发送方接收,并addrSenderOfVideo
包含端口和 ip 号。发件人的 ip 为“127.0.0.1”,这也是包含在addrSenderOfVideo
.