cout<<"Error in setsockopt(IP_ADD_MEMBERSHIP): "< return 0; } //创建了两个线程,一个读用户输入并发送,一个读多播组数据 HANDLE hHandle[2]; hHandle[0] = (HANDLE)_beginthread(do_send,0,(void*)server); hHandle[1] = (HANDLE)_beginthread(do_read,0,(void*)server); //如果用户输入结束,程序就终止了 WaitForSingleObject(hHandle[0], INFINITE); WSACleanup(); return 0; } void do_send(void* arg) { SOCKET server = (SOCKET)arg; char sendline[BUFFER_SIZE+1]; sockaddr_in remote; memset(&remote, 0, sizeof(remote)); remote.sin_addr.s_addr = inet_addr ( MULTICAST_IP ); remote.sin_family = AF_INET ; remote.sin_port = htons(MULTICAST_PORT); for(;;) //读取用户输入知道用户输入"end" { cin.getline(sendline, BUFFER_SIZE); if(strncmp(sendline,"end",3)==0) break; |
正在阅读:读书笔记:在局域网中实现多播功能读书笔记:在局域网中实现多播功能
2004-03-16 15:14
出处:CSDN
责任编辑:linjixiong
键盘也能翻页,试试“← →”键