Sep 4, 2010, 06:11 AM
Hey I started to use these async sockets today, but there is one thing I don't quite get, if I send a socket with tag as 1, it comes to my server and it shows that the tag is still 0, I suppose that the tags are used to identify what operation to perform with the packet? Sorry if this is really dumb question, I read the documentation and didn't quite get it.
Sep 4, 2010, 01:49 PM
Tags are not sent or received over the network.
In the "EchoServer2" zip file, open "AsyncSocket Documentation.html".
Under section 3 "Using AsyncSocket", go to the sub-section "Reading and Writing". The last paragraph is this:
To help the delegate object respond appropriately, you can supply a tag value as an argument of a read or write message. A tag value can be an integer, pointer, or object id. Tag values are not transmitted to the remote socket, and the remote socket does not transmit tag values to the local socket. But the message sent by the local socket to its delegate upon completing the operation includes the tag value you initially supplied. The tag value can be used to “remember” the circumstances under which the operation was initiated. Tag values can mark a type of operation, or specify a step of a multi-operation process.
I've only written code that actively uses tag values once. All the other times I used AsyncSocket (or AsyncUDPSocket), I didn't need or use tag values, so I simply set them all to 0.
I used the tag value to refer to a state in a finite-state machine for the connection. I never expected or intended it to be transmitted or received. Using tags for state is not the only way to do this. It's just the way I happened to do it at that time.