Download

[Plugin] Socket.io Client

Socket.io is a performant real-time bi-directional communication library. There are two parts, the server written in node.js and the client typically javascript for the web. There are alternative client implementations and I’ve used the C++ client library and ported it to UE4.

For the London is Unreal meetup I made a presentation on the topic of plugins and chose to implement a useful plugin live during the presentation. A socket.io client was chosen as the plugin, which was finished with a basic Connect, Bind, Emit functions and an On event all interfaced through an Actor Component.

Since 0.4, the plugin is pretty feature complete, let me know what other features you think are missing!

Download

https://img.shields.io/github/release/getnamo/socketio-client-ue4.svg

Available at:
https://github.com/getnamo/socketio-client-ue4/releases
or
https://www.unrealengine.com/marketp…cket-io-client

Resources
Github Repository - Always contains the latest documentation
Example UMG Chat Project (contains server and both web and ue4 client)
How to connect Unreal Engine 4 to local server via WebSocket using blueprints? - By Egor Bogomyakov

Example project is a functional UMG based chat window place in world showing real-time communication ability of UE4 -> Web/Mobile

Contribute
Still missing SSL via openssl https://github.com/getnamo/socketio-client-ue4/issues

Quick Install & Setup

  1. Download Latest Release
  2. Create new or choose project.
  3. Browse to your project folder (typically found at Documents/Unreal Project/{Your Project Root})
  4. Copy Plugins folder into your Project root.
  5. Restart the Editor and open your project again. Plugin is now ready to use.

How to use - BP Basics

Add the SocketIO Client Component to your blueprint actor of choice

http://i.imgur.com/lSkfHQ2.png

Specify your address and port, defaults to localhost (127.0.0.1) at port 3000. Note that since 0.2.0 connect is optional as the component will auto connect unless you disable autoconnect via boolean.

https://camo.githubusercontent.com/eab6a40ab7c42e3f788ba45b36d879856ebf68b9/687474703a2f2f692e696d6775722e636f6d2f645778436d76512e706e67

Call bind for each event you wish the client to subscribe, e.g. ‘chat message’. If you expect to receive events, select your component and in the Details pane press the + to add an ‘OnEvent’ event to your event graph.

Handle this event for your event types, e.g. printing ‘chat message’ event strings.

https://camo.githubusercontent.com/07876d1bdcd2e43fdace023f4d7e16336bde1788/687474703a2f2f692e696d6775722e636f6d2f76566c4e426c782e706e67

If you want to send information to the server, emit events on the SocketIO Client Component, e.g. pressing M to emit a ‘chat message’ string

https://camo.githubusercontent.com/8a717ed3d46ba6b51912051c73ed42c68b18ff0a/687474703a2f2f692e696d6775722e636f6d2f6e69684d53507a2e706e67

Changelist

See latest changes at https://github.com/getnamo/socketio-client-ue4/releases

0.7.0
-Compile fixes for 4.18
-New Plugin scoped memory architecture for reliable and fast FSocketIONative management. Candidate fixes for #44](https://github.com/getnamo/socketio-client-ue4/issues/44), #45](https://github.com/getnamo/socketio-client-ue4/issues/45), #55](https://github.com/getnamo/socketio-client-ue4/issues/55), #56](https://github.com/getnamo/socketio-client-ue4/issues/56), #57](https://github.com/getnamo/socketio-client-ue4/issues/57), #60](https://github.com/getnamo/socketio-client-ue4/issues/60), and #63](https://github.com/getnamo/socketio-client-ue4/issues/63). If you were having any of those problems, try the new plugin and give it a good test. Re-open if issues persist. Architecture merged in as f17df08
-New optional fully plugin-scoped connections which remain even through level transitions. Tick bPluginScopedConnection true and ensure your component before and after use the same PluginScopedId. Unless disconnect is manually called these type of connections will only close on app exit.
-New OnConnectionProblems callback with verbose signature allowing you to detect when you get disconnected while the socket.io client is still trying to reconnect (default: always trying infinite times). If you wish to change this behavior new parameters have been exposed which control connection attempts and delay.
-New default toggle bVerboseConnectionLog allows you to quiet your log. Default is true.
-Blueprint TMap support added! This should be a massive boost to productivity if you used map like data structures. Issue #59](https://github.com/getnamo/socketio-client-ue4/issues/59) fix merged in f640f63
-Auto-conversion for As String if string type not supplied. Issue #64](https://github.com/getnamo/socketio-client-ue4/issues/64) merged in 2b118c4
-Direct convenience function binds added. This allows you to bind an event or callback to a blueprint function with e.g. String signature only if you know the data type will be a string. See emit with callback section for a list of supported signatures. Issue #65](https://github.com/getnamo/socketio-client-ue4/issues/65) fix merged in 591c150
-FSocketIONative now exposed as API. Issue #66](https://github.com/getnamo/socketio-client-ue4/issues/66) merged in 7e32f70 spotted by GeneralD

0.6.0
-Rebased to accomodate #43](https://github.com/getnamo/socketio-client-ue4/issues/43). You can now put FSocketIONative anywhere with your own allocation structure.
-‘On’ event dispatch changed to ‘OnEvent’.
-Candidate fixes for #41](https://github.com/getnamo/socketio-client-ue4/issues/41), #32](https://github.com/getnamo/socketio-client-ue4/issues/32), and #38](https://github.com/getnamo/socketio-client-ue4/issues/38)
-Fixes to underlying library stopping re connection attempts when you close a connection: getnamo/socket.io-client-cpp@3f0cd99

0.5.2
-Fixed boolean always returning false #35

0.5.1
-Fixed undefined as second emit parameter from server #36

0.5.0
-Fixes for disconnecting while communicating with an unreachable server #32
-Boost updated to 1.62
-Socket.io-cpp updated to latest master merge
-misc internal features for tracking and killing lambda threads

0.4.8
-UTF8 Support
-Connection fixes
-Session ID fix
-Compile fixes for IWYU changes in 4.15
-Scaffolds for other platforms from contributors (non-functioning)

0.4.0
-Added SIOJson for Blueprint Json construction and conversion, based on VaRest
-Auto-conversion for nodes
-Blueprint callbacks and events bound to functions references by function name
-Conversion of JsonObjects to and from UStructs, including Blueprint UStructs with automatically trimmed long names into readable short names
-Overloaded EmitNative for all expect UE native data types
-Much simplified C++ usage based on FJsonValue and FJsonObject including nested binary support (hackery!)
-and much more

0.2.6-0.3.4
-Internal versions for 0.4.0

0.2.5
-Change event names and signatures
-Add wider support for raw message emitting and receiving

0.2.2-0.2.4
-raw sio::message support and events

0.2.1
-added proper binary send/receive support
-added functioning onconnect/disconnect events, no longer require
special events on your server
-added on namespace connect/disconnect events
-added on fail event

0.2.0
-Update to 4.13
-Added connect/disconnect signatures (these have to be implemented by
the server if used)
-Added C++ lambda binds do e.g.
BindDataLambdaToEvent(&](const FString& EventName, const FString& EventData) { //your code }, Name, Namespace);
to use it
-Bind changed name to BindEvent
-Added Namespace support
-Connection runs on background thread (should not be blocking anymore)

0.1.2
-Updated compiled dlls and version for 4.12 (no code changes)

0.1.1
-First release

Presentation slides? >:D

Presentation didn’t have too much technical meat before the actual demo as I did the whole thing live but here are the slides:

And the video shown for the example custom c++ function is found here:
https://www.youtube.com/watch?v=4CgCJsThsWU

What can I say? Bookmarked :stuck_out_tongue:

Thanks Getnamo, really enjoyed your daring live c++ coding demo - glad it wasn’t me. Going to take a proper look at this next week. I’m quite interested in linking libraries so if you’ve got any pointers about that I’d be very interested.

Looks like a plugin I need to add to my tutorial… That is really neat!

teak

Added some basic BP instructions to both the github readme and for convenience, this thread. Going forward the github readme will have all the most up to date documentation.

Great work!

Going to give this 1 a try for some User detail input for an event I have coming up, should save me some time compared to doing REST server!

Any plans for updating this for 4.12?
I’m currently working on a project in 4.12 and could really use this.

Thanks!

Always nice to see someone using this :)! Please do note that the current bind is functional albeit a bit simple since it was done in 30min during the presentation and could use some updates to make event binding a bit easier.

Update to 0.1.2
-Updated compiled dlls and versioning for 4.12 (no code changes)

Grab the latest at the usual spot: Releases · getnamo/socketio-client-ue4 · GitHub

@getnamo Thanks for this awesome socketio client, works well.

but I am not able to use it in executable, it is working when I play in the editor, but when try to Launch as HTML5, Launch Fails.
When I turn off the plugin and then launch project as HTML5, it works.

Is there anything with the compilation? How to use it in executable? Please reply.

The boost and socket.io static libraries that this plugin depends on have only been compiled for the Win32 and Win64 platforms. I’m unsure how plugin dependencies are handled for the ue4 html5 platform as it is not one I develop for and the documentation and questions on building with plugins are scarce and without resolution.

Perhaps someone from epic would be able to chime in on what steps would be required to include static libs for the ue html5 platform?

First, awesome work! And they are really clean to use from Blueprints. I do have one quick question though. I have a node server that I have been using as the backend for Unity and am looking to test it out against UE4, which there wasn’t a client for socket.io when I first looked, so this is awesome!

The issue I am running into is if I pass a JSON object instead of a string, I dont seem to get anything back from the plugin. Are there plans to support more advanced objects?

Thanks!

Edit: Adding screenshot, unless I call JSON.stringify on my objects this always goes to empty string

Ok, one last issue I found, I might go look at the source and see if the 3rd party library is exposing it and it just needs to be wrapped or if it isn’t there.

It looks like the client hears socket.emit but doesnt hear io.emit. Let me see if I can explain that better. On the javascript side there are events that are inside of your existing connection, and those are what I am considering socket.emit, then there are those that are server level that run in the game loop. They fire irregardless of your connection being present or not, though of course I suppress them when noone is connected :slight_smile:

Anyhow, awesome start! If I get time I will poke around at it and do a PR if it is something easy to fix but my C++ is limited at best :slight_smile:

Edit: Sorry, just re-read the first message and noticed you stated this was very basic. Sorry for being silly :slight_smile:

Excellent idea on adding JSON parsing. When I bound the function, due to time constraints and simplicity I do a data->get_string() then convert to UE FString to get a message, seen here: socketio-client-ue4/SocketIOClientComponent.cpp at master · getnamo/socketio-client-ue4 · GitHub

The base library that I integrated uses sio::message as wrapper for JSON objects. This needs to take the received message object and turn it into a JSON string so you can parse it using the blueprint utility you’re using. Off the top of my head I thought get_string() would do that, but apparently it strictly checks for ‘string’ type variables. Looking in the socket.io-client-cpp library source would be the best place to spot how.

Edit: seems the library doesn’t natively support message<->JSON conversion, but a workaround can be found here: Feature Request : Expose sio::message mapping to/from std::string · Issue #87 · socketio/socket.io-client-cpp · GitHub. To add the workaround to the plugin would require adding that function to the component implementation and just call it if we get an empty string from our regular method.

Have you tried io.sockets.emit()? This should work IMO, but it may be down to listening to the broadcast correctly.

I’ve added the two issues here: Issues · getnamo/socketio-client-ue4 · GitHub and this is the link to the underlying library: GitHub - socketio/socket.io-client-cpp: C++11 implementation of Socket.IO client let me know what you discover!

Yes, I poked around a bit at the interface for the base library you used, didn’t even realize the source is out there, that will make things easier. I’ll have to take a look at what it takes to compile a plugin this weekend and see if I can get some more functionality going. Returning the object instead of a string would have actually been more convenient anyhow as I could do just about anything with it once I had that! I did see the base library has that and other magic that can come out.

For the io.sockets.emit(), I think its the same thing, io.emit emits to all active socket connections, but I will take a look and see. I am at work now so I don’t have the notes I took when I looked at the base library unfortunately.

Thanks for the response, sorry for stirring everything up on something that was basically just a prototype :slight_smile:

Hello, first of all thank you very much for your plugin, it’s been very useful to me :slight_smile:
Similarly to DIVYA ADITYA, I needed to use this plugin for another platform (Android), and I was trying to recompile your source code for using it as an Android library (I was going to make you a pull request once I had it all builted and tested, if you might be interested :slight_smile: ). However, I am having several issues even to compile your code and its dependencies. VS2015 for UE4 does’t seem to like websocketpp and boost as dependencies. Did you have to do some particular trick, in order to compile your library with those dependencies?

Yeah the original library source is at GitHub - socketio/socket.io-client-cpp: C++11 implementation of Socket.IO client. If I remember right I had to download boost 1.6 and compile it and then grab Network Graph · zaphoyd/websocketpp · GitHub one of the forks in websocketpp that solved some of the compile issues there. Instead of just adding the prebuilt libraries in the repo, maybe I should find the old source for building those libraries for vs2015, I’ll dig around!

If you do get a successful android build, by all means make pull requests! This is a community plugin, not something exclusive.

Downloaded and I plan on experimenting with your plugin in a little test project. Time to dive back into learning Socket.io and Nodejs!

@getnamo so I found out if the server is unavailable (crashed), the editor completely freezes up and I have to end it.