什
什么年代
Unregistered / Unconfirmed
GUEST, unregistred user!
我的服务端程序
Sockhd := (socket(AF_INET, SOCK_stream, 0)); //Tcp
if Sockhd<0 then begin
messagebox(application.handle,'无法创建句柄!','警告',MB_OK MB_APPLMODAL or MB_ICONWARNING);
exit;
end;
Serv_addr.sin_addr.s_addr:= inet_addr(PChar(edit1.Text)); //主机名
Serv_addr.sin_family := PF_INET;
Serv_addr.sin_port := htons(7000); //any port you want to connect
if bind(Sockhd, Serv_addr, SizeOf(Serv_addr))=SOCKET_ERROR then
begin
showMessage('失败!');
WSACleanup();
exit;
end;
// mcast.imr_multiaddr.s_addr := INADDR_ALLHOSTS_GROUP;
mcast.imr_multiaddr.s_addr := inet_addr('192.168.0.105');
mcast.imr_interface.s_addr := INADDR_ANY;
if (Setsockopt(Sockhd,IPPROTO_IP,IP_ADD_MEMBERSHIP,pchar(@mcast),sizeof(mcast))=SOCKET_ERROR) then
begin
ShowMessage('加入多播组失败,请退出');
WSACleanup(); //加入多播
exit; s
end;
我在局域网里,地址是192。168。0。105,
我希望服务端建立一个多播,客户端加入,为什么Setsockopt出错,
谢谢,改如何写。
Sockhd := (socket(AF_INET, SOCK_stream, 0)); //Tcp
if Sockhd<0 then begin
messagebox(application.handle,'无法创建句柄!','警告',MB_OK MB_APPLMODAL or MB_ICONWARNING);
exit;
end;
Serv_addr.sin_addr.s_addr:= inet_addr(PChar(edit1.Text)); //主机名
Serv_addr.sin_family := PF_INET;
Serv_addr.sin_port := htons(7000); //any port you want to connect
if bind(Sockhd, Serv_addr, SizeOf(Serv_addr))=SOCKET_ERROR then
begin
showMessage('失败!');
WSACleanup();
exit;
end;
// mcast.imr_multiaddr.s_addr := INADDR_ALLHOSTS_GROUP;
mcast.imr_multiaddr.s_addr := inet_addr('192.168.0.105');
mcast.imr_interface.s_addr := INADDR_ANY;
if (Setsockopt(Sockhd,IPPROTO_IP,IP_ADD_MEMBERSHIP,pchar(@mcast),sizeof(mcast))=SOCKET_ERROR) then
begin
ShowMessage('加入多播组失败,请退出');
WSACleanup(); //加入多播
exit; s
end;
我在局域网里,地址是192。168。0。105,
我希望服务端建立一个多播,客户端加入,为什么Setsockopt出错,
谢谢,改如何写。