我用是AsyncSocket.h,AsyncSocket.m看了好多文章上介绍的发送函数
这是我用的服务端的发送函数
-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
NSString *receive = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (receive == NULL)
{
NSLog(@"数据为空");
}
else
{
[self addText:[NSString stringWithFormat:@"%@",receive]];
NSString *recv= [NSString stringWithFormat:@"收到:%@",receive];
NSLog(@"fasong%@",recv);
[s readDataWithTimeout:-1 tag:0];
}下边是我自己写的
-(IBAction)recvData:(id)sender
{
/*NSData *message = [[NSData alloc]init];
[socket readDataToData:message withTimeout:-1 tag:0];
NSString *Str = [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
NSUInteger len = [Str length];
[self addText:[NSString stringWithFormat:@"客户端发送的信息:%@",Str]];
NSLog(@"客户端发送的信息:%@,%lu",Str,len);
[socket readDataWithTimeout:-1 tag:0];*/}
但是这两个没有接收数据啊
didReadData接收到的是什么,是客户端发来的数据吗,还是有SOCDET的数据
我的那个函数可以用吗
这是我用的服务端的发送函数
-(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
NSString *receive = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (receive == NULL)
{
NSLog(@"数据为空");
}
else
{
[self addText:[NSString stringWithFormat:@"%@",receive]];
NSString *recv= [NSString stringWithFormat:@"收到:%@",receive];
NSLog(@"fasong%@",recv);
[s readDataWithTimeout:-1 tag:0];
}下边是我自己写的
-(IBAction)recvData:(id)sender
{
/*NSData *message = [[NSData alloc]init];
[socket readDataToData:message withTimeout:-1 tag:0];
NSString *Str = [[NSString alloc] initWithData:message encoding:NSUTF8StringEncoding];
NSUInteger len = [Str length];
[self addText:[NSString stringWithFormat:@"客户端发送的信息:%@",Str]];
NSLog(@"客户端发送的信息:%@,%lu",Str,len);
[socket readDataWithTimeout:-1 tag:0];*/}
但是这两个没有接收数据啊
didReadData接收到的是什么,是客户端发来的数据吗,还是有SOCDET的数据
我的那个函数可以用吗
解决方案 »
- UIGestureRecognizer手势的疑惑
- IOS phonegap
- 本人新转行移动通讯开发,请教大牛们!
- CAKeyframeAnimation 失效的疑问
- 使用Storyboards创建导航控制器和表视图,表格数据没有显示出来?
- 设置了ARC,为什么还需要@autoreleasepool
- 创建项目出现这个问题:clang: error: linker command failed with exit code 1
- OC中的self与点语法的使用
- cocoapods启动失败:rror: RPC failed; curl 56 SSLRead() return error -9845
- 有大神吗 遇到了一个不知道咋写的demo cell的展开收起
- IOS 应用图标当系统升级IOS7后变会默认
- 100分求解决UIWindow页面跳转问题!!
是Socket组件接收到Socket数据时的回调方法
你写的不能用
(void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag可以接收数据了