简体   繁体   English

GCDAsyncSocket readDataWithTimeout没有继续读取数据

[英]GCDAsyncSocket readDataWithTimeout is not continuing to read data

I am using GCDasyncsocket in my iOS app to send a string over a socket connection and then to read a string every second over the same socket connection. 我在我的iOS应用程序中使用GCDasyncsocket通过套接字连接发送字符串,然后每秒通过同一套接字连接读取字符串。 I am also creating a second socket to the same server on a different port ad reading once a second there as well. 我还在另一个端口广告上创建了到同一服务器的第二个套接字,并且在那里每秒读取一次。

My write is working properly and the first few reads on each socket work properly, but then the connection appears to stop. 我的写入工作正常,并且每个套接字上的前几个读取工作正常,但是随后连接似乎停止了。

My current method of reading every second is to kick off the reads by calling 我当前的每秒读取方法是通过调用开始读取

[asyncSocket readDataWithTimeout:1 tag:1];
[asyncSocket_Emove readDataWithTimeout:1 tag:2];

at the end of "didConnectToHost" and the similarly calling them again at the end of "didReadDatawithTag" 在“ didConnectToHost”的末尾,类似地,在“ didReadDatawithTag”的末尾再次调用它们

I can provide more details if needed, but does anyone have an idea why the socket is stopping? 如果需要,我可以提供更多详细信息,但是没有人知道为什么套接字正在停止吗?

Replace this line 替换此行

[asyncSocket readDataWithTimeout:1 tag:1];

with this 有了这个

[asyncSocket readDataWithTimeout:-1 tag:1];

may work for you. 可能为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM