-(void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext{
NSString * string=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSString * serveAddress=[[NSString alloc]initWithData:address encoding:NSUTF8StringEncoding];
NSLog(@”data:%@=====ip:%@”,string,serveAddress);
}
打印出来的结果,serveAddress为空,怎么正确转码
打印结果:
iosUdpdemo[1041:22500] data:jy9191=====ip:(null)
NSString * string=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSString * serveAddress=[[NSString alloc]initWithData:address encoding:NSUTF8StringEncoding];
NSLog(@”data:%@=====ip:%@”,string,serveAddress);
}
打印出来的结果,serveAddress为空,怎么正确转码
打印结果:
iosUdpdemo[1041:22500] data:jy9191=====ip:(null)
解决方案
20
address是sockaddr结构体,不能这样直接转换成字符串。
GCDAsyncUdpSocket提供一个方法转换。
[GCDAsyncUdpSocket hostFromAddress:address];
希望对你有帮助
GCDAsyncUdpSocket提供一个方法转换。
[GCDAsyncUdpSocket hostFromAddress:address];
希望对你有帮助