Problems with (CC 2.1.2)

Problems with (CC 2.1.2)

i have this simple code in typescript

var sioclient = io.connect(“localhost:52300” );

io its not recognized

On server i have endless connection attempts

It was not recognized by VSCode intellisense.
Cocos Creator native engine (not web) already has socket io.

A good read:

Yes something was wrong with the definitions.
But why the client is connecting múltiple times?

Plz check example project. They have a working codes from where you can learm from.

I already did that. I used the code from the example.

is there a problem with

I’ve no time to play with 2.1.2 yet. It worked fine in 2.1.0, for sure.

But how are you implementing it?
did you download as plugin or did yoou use the from cocos itself?
the documentations says the is not integrated but looks like that in latest version it is packaged with cocos

is NewClass instantiated multiple times? Generally, you should place your socket code inside a singleton. Also, log the disconnect message, and make sure the client isn’t simply connecting->disconnecting->connecting->reconnecting…

I have a node called TestNode with the script Test.ts

inside Test.ts i have this code. I used as example the code from cocos examples,
It tries to connect onLoad

the server detects when a player connectes and disconnects. I tested with ue4 using plugin and it works

now when i play the game from cocos i get this

but server gets this

have you debugged what is causing the disconnect?

As i said. With the ue4 socket client it works fine. So something happens with the client in cocos.

I tested with cocos 2.0.9 and same result.
I tested with Unity and works fine

I created a simple client

the server works ok! so there is something missing in cocos.

What is socketio version at server side?
If you are using 2.x then try with 1.x, it should work.

i’m using –
So there is no way to use it without 1.0 :confused:

ya, try with 1.7.3.
It wont make much difference (AFAIK)

Have you tried to log errors on both client and server side? Generally should have some error before it decides to just disconnect…

ping out

Sorry for not having a quick cut answer, I program with cocos2d-x in C++ so only have generalized ways to help.

Can you make sure the connection is being upgraded from http to websocket? Did you make sure to include transports: [websockets] in the connection… (client side)