Announcement

Collapse
No announcement yet.

[Plugin] Socket.io Client

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

    #76
    Originally posted by edcolmar View Post
    I managed to get the base implementation working. I ripped all of your code out of the plugin to do it though, so it's not really useful as a plugin anymore. I'll post what I did one I get a bit more testing on it.
    Try this branch instead (awaiting a few more tests before merging to master, but it seems solid): https://github.com/getnamo/socketio-...class-refactor

    It's still a plugin and you can make a FSocketIONative wherever you like and use the same methods. E.g. the component spawns it on initialize component https://github.com/getnamo/socketio-...ponent.cpp#L25 but you can use your own life cycle. Instead of the multicast delegate system for connected/disconnected you just use raw lambdas as callbacks, these are set before I connect in the component to forward to the multicast delegates: https://github.com/getnamo/socketio-...onent.cpp#L138
    Last edited by getnamo; 05-02-2017, 09:15 AM.
    Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

    Comment


      #77
      I got connecting and emitting events to work. Yay!

      I'm stuck on how to receive events.

      In your c++ docs:
      https://github.com/getnamo/socketio-client-ue4
      You have:

      OnRawEvent([&](const FString& Name, const sio::message:tr& Message)

      This gives a compilation error:
      no suitable user-defined conversion from "lambda []void (const FString &Name, const sio::message:tr &Message)->void" to "const FString" exists


      Digging through the code, I see you use this instead:
      OnRawEvent(EventName, [&](const FString& Event, const sio::message:tr& RawMessage)

      I can't get this to work either.

      Can you show how to receive events in c++ in context? I feel like I'm doing it totally wrong.

      Comment


        #78
        Originally posted by edcolmar View Post
        I got connecting and emitting events to work. Yay!

        I'm stuck on how to receive events.

        In your c++ docs:
        https://github.com/getnamo/socketio-client-ue4
        You have:

        OnRawEvent([&](const FString& Name, const sio::message:tr& Message)

        This gives a compilation error:
        no suitable user-defined conversion from "lambda []void (const FString &Name, const sio::message:tr &Message)->void" to "const FString" exists


        Digging through the code, I see you use this instead:
        OnRawEvent(EventName, [&](const FString& Event, const sio::message:tr& RawMessage)

        I can't get this to work either.

        Can you show how to receive events in c++ in context? I feel like I'm doing it totally wrong.
        Looks like I missed a key C++ documentation bit, bind events in c++ not using the raw format, thanks for catching this! Generally OnRawEvent should be avoided unless you want to use sio::message data types (these are not UE4 native).

        I've now added the UE4 native section here: https://github.com/getnamo/socketio-...ceiving-events

        Since we're using the FSocketIONative the function is https://github.com/getnamo/socketio-...ONative.h#L212

        So the syntax for that should be:

        Code:
        //Smart pointer method
        TSharedPtr<FSocketIONative> NativeClient; //assuming this is valid
        
        or
        
        //Raw pointer method
        FSocketIONative* NativeClient; //assuming this is valid
        
        ...
        
        NativeClient->OnEvent(FString("MyEvent"), [](const FString& Event, const TSharedPtr<FJsonValue>& Message)
        	{
        		//Called when the event is received
        	}, FString("Optional Namespace"));
        note that you'll need to add variables you use in the lambda capture to
        Code:
        []
        so that they are captured. E.g. if you call the above inside a member function
        Code:
        [this]
        would normally be sufficient. See http://en.cppreference.com/w/cpp/language/lambda for reference on C++ lambdas.
        Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

        Comment


          #79
          Originally posted by getnamo View Post
          thanks for catching this!
          You bet.

          Thanks for the detailed explanation. I'll report back with my findings, after I dig in.

          Comment


            #80
            OnNativeEvent(FString("MyEvent"), [](const FString& Event, const TSharedPtr<FJsonValue>& Message)
            {
            //Called when the event is received
            }, FString("Optional Namespace"));

            Thank you! This is working.

            Comment


              #81
              Update to 0.6.0
              Changes:

              API Changes:
              -Rebased to accomodate #43. You can now put FSocketIONative anywhere with your own allocation structure.
              -'On' event dispatch changed to 'OnEvent'.

              Fixes:
              -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

              You can find the latest release at https://github.com/getnamo/socketio-client-ue4/releases

              If you had crashes with 0.5.2 try 0.6.0 and let me know if that has resolved issues. You should be able to open maps in packaged games with components whether your server is up or not. The only potentially unhandled use case is when you open a map to a server that is up and you swap map after the server status changes (e.g. becomes unreachable/goes down). If you have this use case you can use the workaround of setting bAsyncQuitDisconnect to false in your components (https://github.com/getnamo/socketio-...omponent.h#L54) which will synchronize your disconnects. If you have a lot of components it will add about ~ 1sec per component delay.
              Last edited by getnamo; 05-07-2017, 02:51 PM.
              Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

              Comment


                #82
                Reporting success with my experiments over here, so far.

                Are socket.io "rooms" available to use in this implementation? If so, I'd love to see a quick c++ example on how to listen to one.

                Thanks again getnamo! =)

                Comment


                  #83
                  Originally posted by edcolmar View Post
                  Reporting success with my experiments over here, so far.

                  Are socket.io "rooms" available to use in this implementation? If so, I'd love to see a quick c++ example on how to listen to one.

                  Thanks again getnamo! =)
                  You're welcome

                  Namespaces are supported, it's the optional parameter called Namespace at the end of your function calls e.g Emit and OnEvent. Namespace support was added in 0.4.0, see the related closed issue: https://github.com/getnamo/socketio-client-ue4/issues/9. When you connect to a namespace, you'll get OnNamespaceConnectedCallback. This is all assuming FSocketIONative, the api is very similar for USocketIOClientComponent.
                  Last edited by getnamo; 05-08-2017, 01:43 PM.
                  Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

                  Comment


                    #84
                    [MENTION=548]getnamo[/MENTION]
                    Thank you for putting out this fix so fast! I can confirm that my issues appear to be gone; the editor is no longer crashing nearly as much and switching levels in the packaged project appears to be working now. I still feel like I'm running into issue #44 though. I can switch from my first level where there are seven SocketIO components connected to my server, emit a message read by the server, read a response, and switch. When I switch, the components all disconnect and I can load the second level.

                    However, when this second level finishes it switches back to the first one and crashes in the packaged project. It sends a lot of messages back and forth to the server and has about 11 SocketIO components. These are all showing as disconnected when I log it in the server, but the first level can't open up again. This error is only present in the packaged version. When I switch every component to disable asynchronous switching, this works properly in both the editor and the packaged game.

                    Obviously, this can lead to some load times that are a lot longer than they need to be. Any idea why this is happening or how to fix it? I'm certain that the server is staying completely accessible the whole time.

                    Comment


                      #85
                      Originally posted by getnamo View Post
                      You're welcome

                      Namespaces are supported, it's the optional parameter called Namespace at the end of your function calls e.g Emit and OnEvent. Namespace support was added in 0.4.0, see the related closed issue: https://github.com/getnamo/socketio-client-ue4/issues/9. When you connect to a namespace, you'll get OnNamespaceConnectedCallback. This is all assuming FSocketIONative, the api is very similar for USocketIOClientComponent.
                      I believe "rooms" are different than namespaces. Some of the research I was doing yesterday suggested that namespaces are predefined, and rooms can be created dynamically.

                      http://stackoverflow.com/questions/1...aces-socket-io

                      I was having issues trying to connect to namespaces which were not yet created, which makes sense if they must be pre-defined.

                      Comment


                        #86
                        Originally posted by Rockhopper View Post
                        [MENTION=548]getnamo[/MENTION]
                        Thank you for putting out this fix so fast! I can confirm that my issues appear to be gone; the editor is no longer crashing nearly as much and switching levels in the packaged project appears to be working now. I still feel like I'm running into issue #44 though. I can switch from my first level where there are seven SocketIO components connected to my server, emit a message read by the server, read a response, and switch. When I switch, the components all disconnect and I can load the second level.

                        However, when this second level finishes it switches back to the first one and crashes in the packaged project. It sends a lot of messages back and forth to the server and has about 11 SocketIO components. These are all showing as disconnected when I log it in the server, but the first level can't open up again. This error is only present in the packaged version. When I switch every component to disable asynchronous switching, this works properly in both the editor and the packaged game.

                        Obviously, this can lead to some load times that are a lot longer than they need to be. Any idea why this is happening or how to fix it? I'm certain that the server is staying completely accessible the whole time.
                        I think this is related to the fact that the components don't release all of their memory immediately in the asynchronous case. This then gets caught in UE4's CanaryFail (related but not the same issue: answerhub) which is meant to catch garbage collection memory leaks. My understanding is that the system is not aware that another thread will release the memory when it is complete thus considers this a leak. The solution here would be to have the allocation cycle on something that survives world/level transitions (stack? plugin?).

                        For some reason the pooling of garbage collected objects are different in the editor vs packaged and this is why I think we're getting the situation we have.

                        One potential solution I can think of is using plugin scoped memory allocation. I was experimenting with it earlier and there are some extra functions ready to try it out: https://github.com/getnamo/socketio-...IOClient.h#L36 but after I found a way to encapsulate the memory within the component I considered that cleaner and I didn't pursue it further. With the packaging bug it may be that plugin scoping the memory would be appropriate after all.
                        Last edited by getnamo; 05-09-2017, 02:26 PM.
                        Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

                        Comment


                          #87
                          Originally posted by edcolmar View Post
                          I believe "rooms" are different than namespaces. Some of the research I was doing yesterday suggested that namespaces are predefined, and rooms can be created dynamically.

                          http://stackoverflow.com/questions/1...aces-socket-io

                          I was having issues trying to connect to namespaces which were not yet created, which makes sense if they must be pre-defined.
                          Glancing over the source api again, it doesn't look like the C++ client has anything setup for room use. Do you have javascript examples for socket.io client and server usage? Seeing this used in javascript could help inform how it's supposed to look like in C++.

                          socket.io docs (#2) are as always a bit light on examples; looking at the docs though it seems to be a server only feature for grouping sockets.

                          Some more resources:
                          http://stackoverflow.com/questions/1...s-in-socket-io - shows a client joining a room, but client api doesn't appear to have .join, or are the docs just outdated?
                          Last edited by getnamo; 05-09-2017, 02:21 PM.
                          Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

                          Comment


                            #88
                            Originally posted by getnamo View Post
                            I think this is related to the fact that the components don't release all of their memory immediately in the asynchronous case. This then gets caught in UE4's CanaryFail (related but not the same issue: answerhub) which is meant to catch garbage collection memory leaks. My understanding is that the system is not aware that another thread will release the memory when it is complete thus considers this a leak. The solution here would be to have the allocation cycle on something that survives world/level transitions (stack? plugin?).

                            For some reason the pooling of garbage collected objects are different in the editor vs packaged and this is why I think we're getting the situation we have.

                            One potential solution I can think of is using plugin scoped memory allocation. I was experimenting with it earlier and there are some extra functions ready to try it out: https://github.com/getnamo/socketio-...IOClient.h#L36 but after I found a way to encapsulate the memory within the component I considered that cleaner and I didn't pursue it further. With the packaging bug it may be that plugin scoping the memory would be appropriate after all.
                            Ah, that's really interesting. I'm working entirely with blueprints right now and would like to stick to working that way; do you think there's a way for me to make use of this package scoping?

                            Comment


                              #89
                              Originally posted by Rockhopper View Post
                              Ah, that's really interesting. I'm working entirely with blueprints right now and would like to stick to working that way; do you think there's a way for me to make use of this package scoping?
                              I'll likely need to branch it and try a few things to see if it fixes it. Might be a bit before I get time for socketio plugin pass again. In meantime consider using the async disconnect toggle off.

                              As always you can track the progress of the issue here: https://github.com/getnamo/socketio-...-ue4/issues/44
                              Plugins: Node.js - TensorFlow - Socket.io Client - ZipUtility - Leap Motion - Hydra - Myo - RealSense

                              Comment


                                #90
                                Hi there,

                                so I've tried to get socket.io to work with my unreal project for actually several months now. And sometimes it kind of works but never really, so I very much hope that you guys can help me!

                                I have UE 4.15.2. and socket.io v0.6.0, those should be the up-to-date versions.
                                I've added the socket.io plugin directly to the engine, because when I added it to the project itself, the packaged project wouldn't even start.

                                As long as I only connect to a socket.io client, everything still works fine. But once I try to emit an event, the editor freezes and crashes. It still emits the event though, because I can see that it works. If I package the project like that, it simply won't emit the event.
                                So I don't know what to do here. Best would be, if wouldn't crash in the editor and if it would work in the packaged project. But I'm happy with everything just working in the packaged project, I can deal with a frozen editor.

                                Thanks in advance!

                                Comment

                                Working...
                                X