Table of Contents

Frequently Asked Questions

General issues

Does this asset support visual scripting?

No. This asset is made for developers working with code.

Why are we not creating Units for it?
Creating universal nodes for Socket.IO would cost lots of time and only target very few people. You can however create your own Visual Scripting Units for implementing Socket.IO communications. Implementing specialized units is much easier than creating universal nodes because our asset for example supports variable payload counts and types.

There are assemblies missing

If not already done, please import Json.Net: https://github.com/jilleJr/Newtonsoft.Json-for-Unity/wiki/Install-official-via-UPM

I replaced your Basic asset by the Plus and now I get compiler errors

The PLUS asset has a different architecture and API. You will have to refactor your code.

I replaced your Basic asset by the Plus and now things stopped working

The PLUS asset has a different architecture and API. You will have to refactor your code. The callbacks do no longer receive json strings but objects from now on.
Depending on your code, you might not get compile errors because the library might now be treating your callbacks as generic subscriptions accepting a string.

Game does not connect, not even locally

In most cases this is caused by one of the following reasons:

1. You are using a secure URL (https/wss) but did not correctly configure SSL on your server side – or vice versa!
Try to access the Socket.IO server using a Webbrowser: http(s)://your.server-address.here/socket.io/ Don’t forget the trailing “/” It should say {"code":0,"message":"Transport unknown"} If any browser errors appear, this is your issue. Be sure to use the exact same address as in the unity component at the red position, and set http for unchecked secure connect and https for checked.

2. You are using the wrong port
Socket.IO assumes port 80 (insecure) or 443 (secure). Make sure to enter the correct port if you are using some other. Test access like in solution1 to make sure everything is right

3. Your server (software) does not support the websocket transport
This asset does not support Long-Polling by design. This would not make sense for modern apps and games. Make sure that your server supports websockets.

After uploading, the server it is no longer working but it worked locally

1. Could be an SSL issue
Again: SSL might not be configured correctly (you won’t communicate unencrypted in production, right?) Check SSL as done in the first question, possible solution 1. But this time using the actual server address.

2. The Websocket transport not supported by the server or a proxy in between
This is a whip of rocket science for most developers: Socket.IO for Unity depends on the “websocket” transport and is NOT able to fallback to long-polling. This is why a standard socket.io application might work while the unity asset is not working. Load Balancers, Reverse Proxies, Firewalls and any device/solution between the client and the server could potentially cause issues here. Usually the issue sits on the server side. Most likely – if using one – your load balancer or reverse proxy (like nginx/apache proxying requests through your servers port 80/443 down to a nodejs based server on a different port) is not configured correctly.

Here are some hints for reverse proxy configuration: https://socket.io/docs/v3/reverse-proxy/ This Rocket-Science can easily be tested by writing a web based test application. Have a look at our example ServerCode zip archive. It contains such a test html file. The important thing about it is to only try the websocket transport using the options: https://socket.io/docs/v3/client-initialization/#transports

Transport Adapters

I am using a transport adapter on my server side. Can I connect to this server using your asset?

Easy answer: No.

Complete answer: Under some circumstances yes but you must implement the parser and encoder on your own. We can't assist you here. It will also only work if the basic transport logic stays in place (Engine.IO via websockets). It is a Case-By-Case thing. You can derive a class from Parser and inject it using SocketIOClient.SetParser

Callbacks (On) firing twice after a reconnect

When a reconnect happens, my listeners are invoked twice. After another reconnect three times, and so on. Why?

This is likely an issue in how - or better when - you are calling "On" to register your callbacks.
Registered Callbacks do survive a reconnect, as this is a client side registration. You must not register your callbacks in a "connect" event, except you add some kind of check that it is not being registered twice - or of course if this behaviour is wanted.

See also the official Socket.IO documentation: https://socket.io/docs/v4/client-api/#event-connect

My server is working on postman or Socket.IO JS library but not with your asset. Why?

There are two common resons for this. Both are simply solved:

  1. Server is not accepting websocket transport (directly): Our asset does not connect using long-polling and upgrade but directly opens a websocket connection to the server. This means, the server must accept websockets as an initial transport. This also applies to middleware (Load-Balances, Reverse-Proxies, Web Application Firewalls, ...)
  2. The server is running on a namespace and you did not provide the URL in the correct form: If you need to enter any PATH in postman / JS Library, you will need to specify it DIFFERENTLY in our asset. If postman or the JS library use something like https://host.tld/chat this means the NAMESPACE is "/test", but the PATH is still "/socket.io/" (unless the "path" option is specified additionally). So in our asset you must specify "https://host.tld/socket.io/" and then in the code use io.GetNamespace("/test").

How do I send request headers, for example to provide an oauth token?

Websockets - the underlaying technology of this socket.io implementation - do not officially support request headers (see also this stackoverflow discussion) so this is not directly possible.
Instead, socket.io implements it's own mechanism to send authentication data on connect time, using the method SocketIOClient.SetAuthPayloadCallback - There is an example in our provided example script. The Server-side API does not access a header, but accesses this data using a call like socket.handshake.auth.whatever where whatever is the fieldname in your authentication payload.

This is the only officially supported way to provide data before the actual socket.io connection is established. Another (hacky) workaround could be to provide the token within the connect URI using query parameters.

See also the official Socket.IO documentation: https://socket.io/docs/v4/middlewares/#sending-credentials

If you are in very urgent need of sending headers and you have no other way to circumvent this, and you are using the NATIVE version only, you can try to hack this by editing NativeImplementation.cs and set your headers using ws.Options.SetRequestHeader before the ConnectAsync call. There will be no API and no support for this as long as websockets are no officially extended by Request Headers inlcuding the common browser implementations. You are on your own with this.



WebGL / IL2CPP builds

Connecting fails from SSL-Secured website

Question:I am using WebGL (on an SSL-secured site) and the game does not connect to the server. Why?
Answer: The most common issue is an SSL-misconfiguration. Please make sure that you can access https:///socket.io/ from your browser without any SSL errors or warnings. (A json formatted transport error is fine) Also remember that in modern browsers, a WebGL game delivered via HTTPS may not contact a server using HTTP/WS but only using HTTPS/WSS so this means SSL everywhere or nowhere.

WebGL build not working / SendMessage error in console

Problem: My WebGL build succeeded but it does not communicate to the server. Maybe even the connect is not working at all. In the browser console I can see errors stating that an object does not have a receiver for SendMessage calls.
Solution: This is likely eighter the result of stripped code (see below "Build is crashing at runtime") or the use of an obfuscator. You must make sure that all the method names in class "Firesplash.GameDevAssets.SocketIOPlus.WebGLImplementation.SIOWebGLMessenger" are not obfuscated (obfuscator config) or removed (link.xml). Depending on your obfuscation solution there may be different ways to achieve that.

IL2CPP build throwing missing AOT code errors

Problem: My IL2CPP-Build (WebGL is always IL2CPP) is showing errors like "Attempting to call method ‘System.Collections.Generic.List[…]::.ctor’ for which no AOT code was generated"
Solution: For some reason using arrays in structures does not work on IL2CPP. Try to use Lists instead. struct Foo {public int[] bar;} could break, struct Foo {public List bar;} works.

Build is crashing at runtime

Problem: My WebGL (or other IL2CPP) build using Json.Net is crashing telling me that a constructor or type has not been found.
Solution: Most likely the linker stripped code that is used by Json.Net. You should add a link.xml file to your project which restricts the linker from doing so. Its content depends on your project but here is an example: https://github.com/SaladLab/Json.Net.Unity3D/blob/master/src/UnityPackage/Assets/link.xml

Another possible reason could be the use of an obfuscator.



Mobile Platforms

The asset should work on mobile platforms without any issues if you configure your project correctly.

Android build does not connect to the server

Please make sure, you set this to required in project settings: