MFC发送UDP广播

//VC 6.0   SOCKET相关代码已启动

//客户端主要代码如下:

SOCKADDR_IN addr;

int broad = 1;

SOCKET fd = socket(AF_INET,SOCK_DGRAM,0);

setsockopt(fd,SOL_SOCKET,SO_BROADCAST,(const char *)&broad,sizeof(broad));

addr.sin_addr.Sun.S_addr = INADDR_BROADCAST;

addr.sin_family = AF_INET;

addr.sin_port = htons(1234);

sendto(fd,recved,strlen(recved)+1,0,(SOCKADDR *)&addr,sizeof(SOCKADDR));

posted @ 2012-12-25 17:26  jefffyang  阅读(3438)  评论(0编辑  收藏  举报