Recent projects in the personal center of some things, user avatar upload, download, local cache, level two cache, compression, these have to do, perfectly formed Ah, is also written in the muddle,
When we upload the user picture, to the server to send upload avatar request, generally do a verification, to the server to obtain token verification information, to ensure illegal upload, if not do this then there will be illegal users upload illegal images, so that your server
Bring about an unknown catastrophe.
And the logic of validation is very well written, and there is no difficulty, such as:
Server.sendmessage ("Get token");
Client.receive (String token)
{
Print (token);
if (token! = Local token)
{
Server.sendmessage ("Get token"); re-acquire Token
}
}
It seems very simple, but the general client in the receiving service side of the message back, there will be a phase of the protocol distribution, and then your receive token code will be placed in the agreement distributed there, or in the protocol distribution where to call, if serious failure,
Go again this process, has been to serious use, a bit like recursion, is not feeling a little silly way?
Indeed, this is not elegant, if not a good comment, it will let people can not touch the clue, the following is a very good way to achieve, that is to use the co-process
<summary>
Iterator object used to get token
</summary>
public class Tokenverificationoperation:ienumerator {
public bool MoveNext () {
Debug.logger.Log (Isdown);
Return! Isdown;
}
Public Tokenverificationoperation () {
Zoneserverrequeset.sendportraittokenreq ();
}
public void Reset () {
}
public void Ontoken (string token) {
Isdown = true;
token = token;
}
public bool Isdown {get; set;}
public string Token {get; set;}
Public object Current {get {return null;}}
}
Use time
Public IEnumerator Tokenjy ()
{
Tokenoperation = new Tokenverificationoperation ();
Yield return MB. Startcoroutine (tokenoperation);
if (tokenoperation. Token) {
Startcoroutine (TOKENJY);
}
}
is not feeling this way, very good, at least not everywhere to write code everywhere to find, directly a function inside, in fact, the principle is very simple, unity in the process will actively invoke the implementation of IEnumerator (iterator) MoveNext function, we go to implement this interface
And then in the MoveNext function to determine whether the service side of the message returned, so that through yeild cooperation, so that the process is simplified. Also very easy to understand, simple and clear.
Another hint: The iterator loop to determine the service-side callback method, not recommended for large-scale use, unity, if the association is not used properly, every launch will have a certain GC garbage, ingenious, just fine
Using the coprocessor in Unity to verify the data of the service side