const char* MULTICAST_IP = "224.0.0.99"; //多播组地址 const int MULTICAST_PORT = 2002; //多播组端口 const int BUFFER_SIZE = 1024; void do_send(void* arg); //读取用户输入并发送到多播组线程函数 void do_read(void* arg); //读物多播组数据函数 int main() { WSAData wsaData; if( WSAStartup(MAKEWORD(2,2), &wsaData) != 0 ) { cout<<"Error in WSAStartup"< return 0; } SOCKET server; server = socket(AF_INET, SOCK_DGRAM, 0); //创建一个UDP套接口 cout<<"create socket: "< int ret ; const int on = 1; //允许程序的多个实例运行在同一台机器上 ret = setsockopt(server, SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)); if( ret == SOCKET_ERROR ) { WSACleanup(); cout<<"Error in setsockopt(SO_REUSEADDR): "< return 0; } const int routenum = 10; ret = setsockopt(server,IPPROTO_IP,IP_MULTICAST_TTL,\ (char*)&routenum,sizeof(routenum)); if( ret == SOCKET_ERROR ) { WSACleanup(); |
正在阅读:读书笔记:在局域网中实现多播功能读书笔记:在局域网中实现多播功能
2004-03-16 15:14
出处:CSDN
责任编辑:linjixiong
键盘也能翻页,试试“← →”键