2
AsyncUdpSocket *socket=[[AsyncUdpSocket alloc]initWithDelegate:self];

NSTimeInterval timeout=500;
NSString *request=@"quick_stat";
NSData *data=[NSData dataWithData:[request dataUsingEncoding:NSASCIIStringEncoding] ];
UInt16 port=8081;  
[socket sendData :data toHost:@"255.255.255.255" port:port withTimeout:timeout tag:1];
NSLog(@"begin scan");

如果主机地址是“255.255.255.255”或“192.168.1.255”,将得到

2011-03-30 19:40:34.547 voco[38177:207] AsyncUdpSocket 0x629bf30 收到意外的 CFSocketCallBackType 8。2011-03-30 19:40:34.549 voco[38177:207] 错误域 = NSPOSIXErrorDomain 代码 = 13“权限被拒绝” UserInfo=0x62b4360 {NSLocalizedDescription=Permission denied} 2011-03-30 19:40:34.550 voco[38177:207] 未发送

如果主机地址为“255.255.255.0”或“192.168.0.255”将得到

begin scan

2011-03-30 19:35:48.415 voco[37930:207] AsyncUdpSocket 0x565fea0 收到意外的 CFSocketCallBackType 8。2011-03-30 19:35:48.417 voco[37930:207] 发送

所以我猜不是我的代码造成的。我该如何解决?

4

1 回答 1

1

通过添加 [socket enableBroadcast:YES error:error] 修复;

于 2011-03-31T04:11:39.937 回答