Saturday, 1 April 2017

socket.io infinite Client connection in unity

I got Socket.io in unity asset and tried version check. There was no problem. So, I make the new function. If the client_version is not equal to server's current_function,

    socket.on('Version Req', function(version)
    {
        console.log("user :" + socket.id + "  version : " + version);
        if(version != current_version)
        {
            console.log("Version is not equal");
            socket.emit('Version Upgrade', play_store_url);
        }
});

This is Client code

private void Awake()
{
    GameObject temp = GameObject.Find("Socket_io");
    socket = temp.GetComponent<SocketIOComponent>();
    socket.On("Version check", Version_Check);
    socket.On("Version Upgrade", Version_Upgrade);
}

private void Version_Check(SocketIOEvent e)
{
    string version = UnityEditor.PlayerSettings.bundleVersion;
    JSONObject param = JSONObject.CreateStringObject(version);
    socket.Emit("Version Req", param);
}

private void Version_Upgrade(SocketIOEvent e)
{
    Debug.Log("Good");
}

that the infinite client connection start like this.

user connected :  YfzhwDGDuP3U5EtnAAAA
user :YfzhwDGDuP3U5EtnAAAA  version : 0.1
user connected :  W7W3FGsN8UZwWTj6AAAB
user connected :  DHQiaOOHU3qlerbLAAAK
user connected :  xLea9P3RfjNaOWfnAAAL
user connected :  rQncBWatx3YAgM4oAAAM
user :rQncBWatx3YAgM4oAAAM  version : 0.1
user connected :  unciuErN6CJZuLkoAAAN
user :unciuErN6CJZuLkoAAAN  version : 0.1

... ㅠㅠ i don't know why this thing happens...



via 이후성

No comments:

Post a Comment