Announcement

Collapse
No announcement yet.

[Plugin] Socket.io Client

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [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!

    Contribute
    Currently missing static libs for various platforms see https://github.com/getnamo/socketio-client-ue4/issues

    Download


    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


    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



    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.



    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.



    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



    Changelist

    0.6.0
    -Rebased to accomodate #43. You can now put FSocketIONative anywhere with your own allocation structure.
    -'On' event dispatch changed to 'OnEvent'.
    -Candidate fixes for #41, #32, and #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
    Last edited by getnamo; 05-07-2017, 02:47 PM.
    Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

  • #2
    Presentation slides? >
    Github - YouTube - Unreal Slackers - KITATUS

    Comment


    • #3
      Originally posted by Zarkopafilis View Post
      Presentation slides? >
      Presentation didn't have too much technical meat before the actual demo as I did the whole thing live but here are the slides:
      https://docs.google.com/presentation...it?usp=sharing

      And the video shown for the example custom c++ function is found here:
      https://www.youtube.com/watch?v=4CgCJsThsWU
      Last edited by getnamo; 05-14-2016, 07:10 AM.
      Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

      Comment


      • #4
        What can I say? Bookmarked :P
        Github - YouTube - Unreal Slackers - KITATUS

        Comment


        • #5
          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.

          Comment


          • #6
            Originally posted by getnamo View Post
            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.

            For now this is a basic bind, but may be extended in the future with better documentation. Enjoy!

            Download
            Latest

            Resources
            Github Repository
            Example UMG Chat Project (contains server and both web and ue4 client)

            Example project is a functional UMG based chat window place in world showing real-time communication ability of UE4 -> Web/Mobile
            Looks like a plugin I need to add to my tutorial... That is really neat!

            teak
            "A little bit of nonsense now and then is cherished by the wisest men..."
            -- Willy Wonka

            twitter: @teak421 -- Smooth Zoom Camera Plugin for 4.14+: here.

            Comment


            • #7
              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.
              Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

              Comment


              • #8
                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!

                Comment


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

                  Thanks!

                  Comment


                  • #10
                    Originally posted by sjespers View Post
                    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: https://github.com/getnamo/socketio-client-ue4/releases
                    Last edited by getnamo; 06-16-2016, 03:40 PM.
                    Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

                    Comment


                    • #11
                      [MENTION=548]getnamo[/MENTION] 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.

                      Comment


                      • #12
                        Originally posted by DIVYA ADITYA View Post
                        [MENTION=548]getnamo[/MENTION] 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?
                        Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

                        Comment


                        • #13
                          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

                          Click image for larger version

Name:	json.png
Views:	1
Size:	78.1 KB
ID:	1111808
                          Last edited by bot2600; 07-10-2016, 07:45 PM. Reason: Added Blueprint

                          Comment


                          • #14
                            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

                            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

                            Edit: Sorry, just re-read the first message and noticed you stated this was very basic. Sorry for being silly
                            Last edited by bot2600; 07-11-2016, 12:39 AM. Reason: Silliness

                            Comment


                            • #15
                              Originally posted by bot2600 View Post
                              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

                              ...
                              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: https://github.com/getnamo/socketio-...ponent.cpp#L41

                              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: https://github.com/socketio/socket.i...-cpp/issues/87. 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.

                              Originally posted by bot2600 View Post
                              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

                              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

                              Edit: Sorry, just re-read the first message and noticed you stated this was very basic. Sorry for being silly
                              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: https://github.com/getnamo/socketio-client-ue4/issues and this is the link to the underlying library: https://github.com/socketio/socket.io-client-cpp let me know what you discover!
                              Last edited by getnamo; 07-11-2016, 10:40 AM.
                              Plugins: TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense - CIM

                              Comment

                              Working...
                              X