floatinghotpot / socket.io-unity

socket.io client for Unity, power game client with node.js back-end
494 stars 75 forks source link

Client Socket Options #12

Open oofaustoo opened 6 years ago

oofaustoo commented 6 years ago

I will apologize in advance for the "newbie" question, but I am in a steep learning curve for Unity, C#, socketIO and node.js, BUT I would like to configure some client socket options when I create my IO.Socket object per:

var socket = IO.Socket("http://localhost:3000");

I see that there are available options:

    public bool Reconnection;
    public int ReconnectionAttempts;
    public long ReconnectionDelay;
    public long ReconnectionDelayMax;
    public long Timeout;
    public bool AutoConnect

But alas I am unable to find the magic incantation necessary.

I suspect it's in the realm of:

var socket = IO.Socket("http://localhost:3000", { some values in a dictionary });

??

Many thanks in advance if anyone is still around and listening.

oofaustoo commented 6 years ago

To answer my own question:

        IO.Options sockopts = new IO.Options();

        sockopts.Reconnection = true;
        sockopts.ReconnectionAttempts = 10000;
        sockopts.ReconnectionDelay = 10000;
        sockopts.ReconnectionDelayMax = 10000;
        sockopts.Timeout = 500;
        sockopts.AutoConnect = true;

        socket = IO.Socket (serverURL, sockopts);

That works fine, but my client appears to only be attempting a single reconnection...

When I stop my node.js server:

Disconnected from server (EVENT_DISCONNECT) Attempting reconnect (EVENT_RECONNECT_ATTEMPT) Reconnecting (EVENT_RECONNECTING)

I get nothing after this... Shouldn't the client attempt ReconnectionAttempts before giving up?