asyncSocket发送照片回服务器,点击发送button可以发送一张图片,点击多次button可以发送多张图片。但是想实现点击一次button循环发送多张图片,无法实现,只能发送最后一张。求大神帮忙!!!
-(void)sendBtnClick:(id)sender { _asyncSocket = nil; for (int i = 0; i<3; i++) { NSLog(@"第%d次",i); [self send]; } } -(void)send { if (!_asyncSocket) { _asyncSocket = [[AsyncSocket alloc]initWithDelegate:self]; NSString *host = @"172.17.73.123"; int nPort = 8484; NSError *error = nil; //[_asyncSocket connectToHost:host onPort:nPort error:&error]; if ([_asyncSocket connectToHost:host onPort:nPort withTimeout:5 error:&error]) { NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"1.jpg"], 1); [_asyncSocket writeData:imageData withTimeout:-1 tag:1]; }else{ NSLog(@"无法连接,原因是:%@",error); } } sleep(5); }
#pragma delegate - (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err { NSLog(@"Info___willDisconnectWithError\n"); NSLog(@"%@",err); [sock disconnectAfterWriting]; }
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port { NSLog(@"Info___didConnectToHost\n"); NSLog(@"Socket did Connect to host: %@:%u", host, port); _asyncSocket = nil; [sock disconnectAfterWriting]; }
控制台输出情况:
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"1.jpg"], 1); 这行里的图片名称不应该固定死,否则你每次上传的都是1.jpg都会覆盖之前上传的。
。。。。。。。
您好 ,请问你用socket上传图片的demo还有吗?发我一份 576484150@qq.com 小弟不胜感激!谢谢!
您好,请问你最近也在做socket上传图片的小项目?有demo可以发一份到我的邮箱 1753321975@qq.com 可以吗?谢谢~
楼主,你好我最近在倒弄利用socket进行设备间的传输,请问下你有小demo吗?有demo可以发一份到我的邮箱 1753321975@qq.com 可以吗?谢谢~