iOS 开发,基于GCDAsyncSocket的即时通讯,是怎样在两个用户间实现的??大概说下过程

 我来答
打伞鱼Aw
2016-04-10 · TA获得超过7266个赞
知道大有可为答主
回答量:7524
采纳率:90%
帮助的人:1603万
展开全部
I think you're slightly misunderstanding the tag concept. The read operations aren't saying "Read data that has been tagged as 2". They are saying "Read the next data off the wire, and tag it as 2 for future reference."
The tag is never sent over the wire - the server didn't tag the data and send it to the client to read. It's a completely optional concept only used to distinguish local operations from each other. In other words, The data being read has no tag. The tag is something you assign to the read operation, so you can identify it later once it's complete.
For example, say you're reading data as a series of headers and payloads. You could use the tag to distinguish a header read from a payload read:
const NSInteger kHeaderTag = 1;
const NSInteger kPayloadTag = 2;

// Assume you know to expect a header, so tag the read operation as such.
[self readDataWithTimeout:-1 tag:kHeaderTag];

// Next assume you know to expect a payload, so tag the read operation as such.
[self readDataWithTimeout:-1 tag:kPayloadTag];

Then you can identify it later...
- (void)socket:(GCDAsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag
{
if (tag == kHeaderTag)
{
// Handle header
}
else if (tag == kPayloadTag)
{
// Handle payload
}
}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式