GCDAsyncUdpSocket发送数据的问题
各位老师, 我发送数据时遇到个奇怪的问题,发送“123”这样的简单数据是没问题的,但是如果发送的是图片数据,就不成功了,
GCDAsyncUdpSocket代理的didSendDataWithTag方法根本不回调。不知道是哪里的问题?
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
//本地显示
UIImage *image = [self imageFromSampleBuffer:sampleBuffer];
[_sourceImageView performSelectorOnMainThread:@selector(setImage:)
withObject:image waitUntilDone:YES];
NSData *data = UIImageJPEGRepresentation(image, 1.0);
if (_udpRunning && data.length > 0) {
/*
NSMutableData *writedata = [NSMutableData data];
UInt32 length = (UInt32)data.length;
[writedata appendData:[self bytesFromUInt32:length]];//先添加4个字节的长度
[writedata appendData:data];//再添加数据
//withTimeout: 超时时间 -1 表示不设置写入缓存的超时
//tag: 一个标识
[_udpSocket sendData:writedata toHost:_targetIp port:_targetUdpPort withTimeout:-1 tag:100];
NSLog(@"--writing----%ld-", (unsigned long)writedata.length);
*/
NSString *msg = @"123";
NSData *data = [msg dataUsingEncoding:4];
[_udpSocket sendData:data toHost:_targetIp port:_targetUdpPort withTimeout:-1 tag:100];
}
}