Sure I can give you whole example as it’s very easy, it is clean ThirdPersonExample with starter content with custom GameMode containing only what you can see on screens. It is running with dedicated server in the background with 1 client. Engine version is 4.15.1 here are the screens from Unreal:
That’s great! That said it’s still a bug from the plugin side, looks like I don’t handle an empty message case on receive, I’ll add another type check in there in case the JsonValue you get is none and see if that will fix it.
From 0.5.0
-Fixes for disconnecting while communicating with an unreachable server #32](https://github.com//socketio-client-ue4/issues/32)
-Boost updated to 1.62
-Socket.io-cpp updated to latest master merge
-misc internal features for tracking and killing lambda threads
This is now fixed in 0.5.1 allowing you to leave the second parameter empty.
@Dannington@Avatarochnik and anyone else who has had disconnect crashes, try the latest version for 4.15 (0.5.2) and let me know if the crashes and hangs have gone away.
My PC is currently in a box coming back from France, but i’ll test it as soon as I get back. Something I realised is that I nearly always do my builds as development builds rather than shipping so I can get access to the console, but for a presentation I did yesterday I made a shipping build and it was a lot less likely to crash (It did only once over the last 3 days on exit, whereas with a development build it would happen more often than not).
Thanks for this @! I would like to use this within an Online Subsystem. Is it possible? Do you have any suggestions on how to implement the client in c++ at this (sub actor) level?
I should be able to refactor the plugin to encapsulate the C++ functionality in a pure C++ class e.g. FSocketIOClient which can then be used as a rebase for the ActorComponent (keep a local shared ptr, and forward all calls). This would allow you to add it anywhere in C++ via raw ptrs e.g. new FSocketIOClient or shared ptrs e.g. MakeSharedPtr(new FSocketIOClient) and not break any ActorComponent functionality while keeping a common core.
@ I did some more testing. As far as I can tell, yes, it only happens in packaged builds. Doesn’t matter if it’s packaged for shipping or development. Using Windows 64-bit build.
The situation is this: I load into a level just fine. Then I have seven blueprints with SocketIO components which all connect properly to my server. Everything is fine.
Then one of these seven blueprints emits a signal to the server, all of them disconnect from the server, and then I switch the level.
I’ll PM you the logs, but it doesn’t look like it’s too helpful. I’ve narrowed it down to the disconnecting step causing the crash in the packaged version. It works without hitch in the editor. Thanks!
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.
This gives a compilation error:
no suitable user-defined conversion from “lambda ]void (const FString &Name, const sio::message::ptr &Message)->void” to “const FString” exists
Digging through the code, I see you use this instead:
OnRawEvent(EventName, &](const FString& Event, const sio::message::ptr& 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).
//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
]
so that they are captured. E.g. if you call the above inside a member function
OnNativeEvent(FString(“MyEvent”), ](const FString& Event, const TSharedPtr<FJsonValue>& Message)
{
//Called when the event is received
}, FString(“Optional Namespace”));
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//socketio-client-ue4/blob/master/Source/SocketIOClient/Public/SocketIOClientComponent.h#L54) which will synchronize your disconnects. If you have a lot of components it will add about ~ 1sec per component delay.