GCDAsyncUdpSocket发送数据的问题

qianlima210210 2017-02-17 10:32:37
各位老师, 我发送数据时遇到个奇怪的问题,发送“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];

}
}
...全文
395 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧