标签:数据传输 add read stream sse ram sage oid nbsp
tag參数是为了在回调方法中匹配发起调用的方法的,不会加在数据传输中。
需注意的一点是:发送时的tag和接收时的tag是无关的。
在CFStream中的回调方法中,会取theReadQueue最新的一个,在回调方法中取得tag,并将tag传
给回调方法:
- (void)onSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag;
如此而已。
官方解释:
In addition to this you‘ve probably noticed the tag parameter. The tag you pass during the read/write operation is passed back to you via the delegate method once the read/write operation completes.
It does not get sent over the socket or read from the socket. It is designed to help simplify the code in your delegate method. For example, your delegate method might look like this:
#define TAG_WELCOME 10
#define TAG_CAPABILITIES 11
#define TAG_MSG 12
...
- (void)socket:(AsyncSocket *)sender didReadData:(NSData *)data withTag:(long)tag
{
if (tag == TAG_WELCOME)
{
// Ignore welcome message
}
else if (tag == TAG_CAPABILITIES)
{
[self processCapabilities:data];
}
else if (tag == TAG_MSG)
{
[self processMessage:data];
}
标签:数据传输 add read stream sse ram sage oid nbsp
原文地址:http://www.cnblogs.com/mthoutai/p/7200236.html