因为在UDP中每次RecvFrom获WSARecvFrom会传回UDP数据来源的IP,因此可以将以上数据结构修改成: typedef struct _PER_IO_OPERATION_DATA { OVERLAPPED Overlapped; WSABUF DataBuff; char Buff[24]; unsigned long recvBytes; //存储接收到的字节数 SOCKADDR_IN remoteAddr; //存储数据来源IP地址 int remoteAddrLen;...
intret = recvfrom(sock, buf,512,0,(structsockaddr*) &clientAddr,&clientAddrLen ); printf("Recv msg:%s from IP:[%s] Port:[%d]\n", buf,inet_ntoa(clientAddr.sin_addr),ntohs(clientAddr.sin_port)); // 发一个数据包返回给客户 sendto(sock,"Hello World!",strlen("Hello World!"),0,...
recvfrom: EFAULT/487/Bad address/10014/The system detected an invalid pointer address in attempting to use a pointer argument in a call ... which reeks of Windows' way of telling me about a SIGSEGV, I guess? :) The recvfrom() implementation itself is a tad too cosmopolitan-specific and...
39 num = recvfrom(sockfd, buf, MAXDATASIZE, 0, (struct sockaddr *)&client, &len); 40 if(num < 0) 41 { 42 perror("recvfrom() error.\n"); 43 exit(1); 44 } 45 buf[num] = '\0'; 46 printf("You got a message <%s> from client. \nIt's ip is %s, port is %d. \n",...
因为在UDP中每次RecvFrom获WSARecvFrom会传回UDP数据来源的IP,因此可以将以上数据结构修改成: typedef struct _PER_IO_OPERATION_DATA { OVERLAPPED Overlapped; WSABUF DataBuff; char Buff[24]; unsigned long recvBytes; //存储接收到的字节数 SOCKADDR_IN remoteAddr; //存储数据来源IP地址 ...