[Plugin] Socket.io Client

Nice work! Thank you for your great plugin!
I have a problem. As far as I understand, the only way to use this plugin is to have an ‘master’ actor and attach ‘SocketIOClientComponent’ to make it running. But in this way, I have difficulties in map switching.
Because the ‘master’ needs to be keep alive between levels, in order to maintain the socket connection. But after some investigation, it seems pretty hard to keep actors alive after map switching.(https://forums.unrealengine.com/showthread.php?3435-Keeping-Actors-Between-Levels, and seamless traveling is not supported in PIE)

I am wondering if there are any ways to solve this problem.

Thank you!

If the SocketIOClientComponent is not appropriate for your use case, you can drop down to the native C++ class FSocketIONative](https://github.com//socketio-client-ue4#c-fsocketionative) which you can manually manage the lifetime using smart pointers (e.g. TSharedPtr<FSocketIONative> ) or raw new/delete. The component uses this internally so check out https://github.com//socketio-client-ue4/blob/master/Source/SocketIOClient/Private/SocketIOClientComponent.cpp for an example use case.

You can also check out ways to keep actors alive throughout map transitions:

Or you can allow a new socketio component to reconnect when a map loads using e.g. a unique token to synchronize the old state/re-emit any required events. I’d generally recommend this structure as it is the only one that allows you to keep a blueprint only workflow. If you can think of a better blueprint supported workflow, give an example and we can try to figure out a way to make it happen.

Note that multiple simultaneous SocketIOClientComponents are possible, and this plugin doesn’t have an opinion on just having one master actor to connect to a server. The components are fairly lightweight and I’ve done tests with up to ~1000 of them in a single level (I recommend to use fewer than 40 simultaneously in real use cases however).

Hello, after searching information i dont know what i should do to package project with this plugin. I add plugin to project build.cs and set in uplugin file “installed- true” I always have error with UE4-SIOJson.lib no mater what i do package project in unreal 4.17.1, or try compile in VS2017 . Just for example this log from unreal:If anyone know right action to decide this i would glad to learn it. [SPOILER] UATHelper: Packaging (Windows (32-bit)): Running AutomationTool…
UATHelper: Packaging (Windows (32-bit)): Automation.ParseCommandLine: Parsing command line: -ScriptsForProject=F:/UnrealProjects/HarvySport/HarvySport.uproject BuildCookRun -nocompile -nocompileeditor -installed -nop4 -project=F:/UnrealProjects/HarvySport/HarvySport.uproject -cook -stage -archive -archivedirectory=“F:/new folder” -package -clientconfig=Devel
opment -ue4exe=UE4Editor-Cmd.exe -pak -prereqs -nodebuginfo -targetplatform=Win32 -build -utf8output
UATHelper: Packaging (Windows (32-bit)): BuildCookRun.SetupParams: Setting up ProjectParams for F:\UnrealProjects\HarvySport\HarvySport.uproject
UATHelper: Packaging (Windows (32-bit)): Project.Build: ********** BUILD COMMAND STARTED **********
UATHelper: Packaging (Windows (32-bit)): CommandUtils.Run: Run: F:\Program Files\Epic Games\UE_4.17\Engine\Binaries\DotNET\UnrealBuildTool.exe HarvySport Win32 Development -Project=F:\UnrealProjects\HarvySport\HarvySport.uproject F:\UnrealProjects\HarvySport\HarvySport.uproject -NoUBTMakefiles -remoteini=“F:\UnrealProjects\HarvySport” -skipdeploy -noxge -g
eneratemanifest -NoHotReload
UATHelper: Packaging (Windows (32-bit)): CommandUtils.Run: Run: Took 1,0965408s to run UnrealBuildTool.exe, ExitCode=0
UATHelper: Packaging (Windows (32-bit)): CommandUtils.Run: Run: F:\Program Files\Epic Games\UE_4.17\Engine\Binaries\DotNET\UnrealBuildTool.exe HarvySport Win32 Development -Project=F:\UnrealProjects\HarvySport\HarvySport.uproject F:\UnrealProjects\HarvySport\HarvySport.uproject -NoUBTMakefiles -remoteini=“F:\UnrealProjects\HarvySport” -skipdeploy -noxge -N
oHotReload -ignorejunk
UATHelper: Packaging (Windows (32-bit)): UnrealBuildTool: Performing 13 actions (4 in parallel)
UATHelper: Packaging (Windows (32-bit)): UnrealBuildTool: ERROR: UBT ERROR: Failed to produce item: F:\UnrealProjects\HarvySport\Plugins\socketio-client-ue4\Binaries\Win32\UE4-SIOJson.lib
UATHelper: Packaging (Windows (32-bit)): UnrealBuildTool: Total build time: 5,19 seconds (Local executor: 0,00 seconds)
UATHelper: Packaging (Windows (32-bit)): CommandUtils.Run: Run: Took 5,3766014s to run UnrealBuildTool.exe, ExitCode=5
UATHelper: Packaging (Windows (32-bit)): Program.Main: ERROR: AutomationTool terminated with exception: AutomationTool.CommandUtils+CommandFailedException: Command failed (Result:5): F:\Program Files\Epic Games\UE_4.17\Engine\Binaries\DotNET\UnrealBuildTool.exe HarvySport Win32 Development -Project=F:\UnrealProjects\HarvySport\HarvySport.uproject F:\UnrealP
rojects\HarvySport\HarvySport.uproject -NoUBTMakefiles -remoteini=“F:\UnrealProjects\HarvySport” -skipdeploy -noxge -NoHotReload -ignorejunk. See logfile for details: ‘UnrealBuildTool-2017.09.11-04.11.32.txt’
UATHelper: Packaging (Windows (32-bit)): в AutomationTool.CommandUtils.RunAndLog(String App, String CommandLine, String Logfile, Int32 MaxSuccessCode, String Input, ERunOptions Options, Dictionary2 EnvVars, SpewFilterCallbackType SpewFilterCallback) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.CommandUtils.RunAndLog(CommandEnvironment Env, String App, String CommandLine, String LogName, Int32 MaxSuccessCode, String Input, ERunOptions Options, Dictionary2 EnvVars, SpewFilterCallbackType SpewFilterCallback)
UATHelper: Packaging (Windows (32-bit)): в AutomationTool.CommandUtils.RunUBT(CommandEnvironment Env, String UBTExecutable, String CommandLine, String LogName, Dictionary2 EnvVars) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.CommandUtils.RunUBT(CommandEnvironment Env, String UBTExecutable, FileReference Project, String Target, String Platform, String Config, String AdditionalArgs, String LogName, Dictionary2 EnvVars)
UATHelper: Packaging (Windows (32-bit)): в AutomationTool.UE4Build.BuildWithUBT(String TargetName, UnrealTargetPlatform TargetPlatform, String Config, FileReference UprojectPath, Boolean ForceMonolithic, Boolean ForceNonUnity, Boolean ForceDebugInfo, Boolean ForceFlushMac, Boolean DisableXGE, String InAddArgs, Boolean ForceUnity, Dictionary2 EnvVars) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.UE4Build.Build(BuildAgenda Agenda, Nullable1 InDeleteBuildProducts, Boolean InUpdateVersionFiles, Boolean InForceNoXGE, Boolean InUseParallelExecutor, Boolean InForceNonUnity, Boolean InForceUnity, Boolean InShowProgress, Dictionary2 PlatformEnvVars, Nullable1 InChangelistNumberOverride, Diction
ary2 InTargetToManifest) UATHelper: Packaging (Windows (32-bit)): в Project.Build(BuildCommand Command, ProjectParams Params, Int32 WorkingCL, ProjectBuildTargets TargetMask) UATHelper: Packaging (Windows (32-bit)): в BuildCookRun.DoBuildCookRun(ProjectParams Params) UATHelper: Packaging (Windows (32-bit)): в BuildCookRun.ExecuteBuild() UATHelper: Packaging (Windows (32-bit)): в AutomationTool.BuildCommand.Execute() UATHelper: Packaging (Windows (32-bit)): в AutomationTool.Automation.Execute(List1 CommandsToExecute, Dictionary2 Commands) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.Automation.Process(String] Arguments) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.Program.MainProc(Object Param) UATHelper: Packaging (Windows (32-bit)): в AutomationTool.InternalUtils.RunSingleInstance(Func2 Main, Object Param)
UATHelper: Packaging (Windows (32-bit)): в AutomationTool.Program.Main()
UATHelper: Packaging (Windows (32-bit)): Program.Main: AutomationTool exiting with ExitCode=5 (5)
UATHelper: Packaging (Windows (32-bit)): BUILD FAILED
PackagingResults: Error: Unknown Error[/SPOILER]
Update: Compile in VS2017 and package in UE4 success but only in win64, in win32 i still get error and in VS2017 get MSB3075…
-waitmutex" exited with code 5. Please verify that you have sufficient rights to run this command.

Is it related to https://github.com//socketio-…ue4/issues/62 ? try altering your .uplugin to Default to SIOJson.

Hi Everybody!
Has anyone tried to use the socket.io UE4 plugin on Unreal Engine 4.18?

Is it compatible at the moment?

The git master repo is now UE 4.18 compatible (since 0.6.5). If you don’t mind compiling the plugin yourself you can grab it at https://github.com//socketio-client-ue4. I’m however still looking to fix an outstanding issue or two before releasing a 4.18 binary.

I am trying to integrate the plugin in my own editor plugin module using the non-actor-component approach. Added the entry “SocketIOClient” in publicdependencymodule list as well as private and public include paths in PublicIncludePaths and PrivateIncludePaths. No error when I include the “SocketIONative.h” in my PCH and declare a TSharedPtr<FSocketIONative> it compiles but when I create the object through Makesharable then I get the “error LNK2019: unresolved external symbol “public: __cdecl FSocketIONative::FSocketIONative(void)”” error. Using 4.16.

Some sanity checks: Does the SIOClientComponent method work?

I’m assuming you’re following the guide https://github.com//socketio-client-ue4#setup which should work, but I haven’t tested making FSocketioNative across module boundaries. You can try adding SOCKETIOCLIENT_API infront of https://github.com//socketio-client-ue4/blob/master/Source/SocketIOClient/Public/SocketIONative.h#L15, let me know if that works.

Adding SOCKETIOCLIENT_API did the trick.
Thanks

**Plugin Update to 0.7.0

Changes**

This is a big update. Lot’s of potential crashes should now be fixed with the new architecture, there’s a new plugin scoped connection type, a new callback for connection problems, a few productivity enhancements when using blueprints, and misc utility stuff.

Kindly test it and let me know if new bugs creep up!

Grab it at the usual https://github.com//socketio-client-ue4/releases

Hi! I have a question, is there any way to transform the chat widget to a UMG 2D component? I’d like to “attach” it to a player’s screen/camera lika a common chatbox, and rendering it like a 3D asset it’s quite tricky for my needs x)

Thanks!

You probably want to read up on how to add widgets to game UI, see Creating Widgets in Unreal Engine | Unreal Engine 5.3 Documentation. I’m assuming you’re using the example project, https://github.com//socketio-client-ue4-example, in that case you want to attach the *sioclient/Content/ExampleContent/ChatBoxWidget.uasset *to your game UI.

Thanks for the answer! I know how to create widgets and put them into the viewport, but I’m having trouble migrating the logic from the ChatWindowActor (to open the input text and send messages etc.) to my character (casting problems in a different places, such as in the function SetupWidgetLinks). What procedure should I follow to achieve it? I’m kinda lost :frowning:

Edit: okay, I think I managed to get it working. I had to make my character inherit from the ChatEmitter interface, and that was almost it. I also have got a reference of my chatboxwidget (just added to the viewport) to link it with the messages.

Thanks!

Hi !
First of all, congrats on your awesome plugin work, you are awesome!
I wanted to ask you something about Linux cross-compiling, as I’m trying to compile a Linux Server with your plugin but it fails in this line:

PrivateClient->connect(StdAddressString, QueryMap, HeadersMap);

With this message:

SocketIONative.cpp:51: undefined reference to sio::client::connect(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > > > const&, std::__1::map<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator >, std::__1::less<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > >, std::__1::allocator<std::__1::pair<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const, std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > > > > const&)'`

What is your Linux compiling setup? I’m using the basic config for cross-compile that is shown in the Unreal Engine wiki.

thank you!

Hi !

I’ve encountered a problem when switching to reliable (with acknowledge) messages from server to client.
I’ve saw your implementation of Emit with Callback that allows the server to reply affirmative if it successfully received a message from the client, but now I need to implement the other acknowledgment direction (get a callback from client after a server emit).

To accomplish this, I think that I need to call a server defined function from the client, but the OnEvent (SocketIOClient) event only have two arguments instead of the required three (the actual implementation have Event and Message JSON but in order to accomplish this it should have Event, Message JSON and Server Ack Function)

Is it possible to extend the behaviour of the OnEvent implementation and enable it to reply a server acknoledgement request by function?

On the below link you can find some references:
https://socket.io/docs/server-api/#socketemiteventname-args-ack

And here you find the important code snippet:
io.on(‘connection’, (socket) => { socket.emit(‘an event’, { some: ‘data’ }); socket.emit(‘ferret’, ‘tobi’, (data) => { console.log(data); // data will be ‘woot’ }); // the client code // client.on(‘ferret’, (name, fn) => { // fn(‘woot’); // }); }); Thanks in advance!

Meanwhile, I’ve used another emit instead of callback and implemented a proprietary message id dequeue system (for reliability).
Anyway, I think this could be an interesting feature for future releases :slight_smile:

Agreed. This would need a little think on how to create a callback reference in blueprint so I’ve added it to issues as an enhancement here: https://github.com//socketio-client-ue4/issues/79

Thanks a lot you are so awesome!
Can’t wait to try it :slight_smile:

Hey,

running a bit of a headache here, i’d appreciate any help with this great plugin.
i’m using a button to connect and disconnect ( not using the auto-connect ).

my problem is, if you connect - disconnect - connect, the connection will fail, if you try to connect again while connection is failing, this crash happens :



Fatal error: [File:D:\Build\++UE4+Release-4.19+Compile\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMemory.cpp] [Line: 183] Ran out of memory allocating 787246532583 bytes with alignment 0

KERNELBASE
UE4Editor_ApplicationCore
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_Core
UE4Editor_SocketIOClient!std::_Allocate<std::_Default_allocate_traits<1> >()
UE4Editor_SocketIOClient!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::assign()
UE4Editor_SocketIOClient!sio::client_impl::connect()
UE4Editor_SocketIOClient!<lambda_599c41d4c2235fe6cf505ad2fc4823d6>::operator()() [c:\XXX\plugins\socketio-client-ue4-master\source\socketioclient\private\socketionative.cpp:51]
UE4Editor_CoreUtility!FLambdaRunnable::Run() [c:\XXX\plugins\socketio-client-ue4-master\source\coreutility\private\lambdarunnable.cpp:47]
UE4Editor_Core
UE4Editor_Core
kernel32
ntdll


kindly post issue to https://github.com//socketio-client-ue4/issues with plugin version and steps to reproduce.
Cheers for bug catching!