SocketIOClient-Unreal icon indicating copy to clipboard operation
SocketIOClient-Unreal copied to clipboard

Connect via URL instead of IP

Open MykonCodes opened this issue 8 years ago • 19 comments

Hey.

Currently having no success establishing a connection when using an URL as the parameter for the Connect function instead of an IP Adress. We'll be using a load balancer and therefore the IP of our servers will change. Is there any integrated way of connecting to an URL instead?

All the best, Mykon

MykonCodes avatar Mar 04 '18 01:03 MykonCodes

This already works, e.g. https://github.com/getnamo/tensorflow-ue4-examples/blob/master/Content/ExampleAssets/Blueprints/ConnectedTFMnistActor.uasset uses http://qnova.io:3000 for the address and port to support web-based input for classification.

Just make sure you specify both url and port http://{your url}:{socketio port}. Default http port btw is 80.

getnamo avatar Mar 04 '18 01:03 getnamo

Thanks for the quick response, however that doesn't work for us.

The logger of the underlying socketIO impl do not output to the UE4 logs, but with manual debugging I found the error code being "pass_through - Underlying Transport Error". No clue what that means. Tried it with port, without, with leading http:// and https:// and without. And those IP's that do work resolve to the exact same IP's. JS SocketIO has no issue connecting to the same URL's.

MykonCodes avatar Mar 04 '18 01:03 MykonCodes

NB: https isn't currently supported see https://github.com/getnamo/socketio-client-ue4/issues/39. Make sure you're not using SSL

getnamo avatar Mar 04 '18 01:03 getnamo

I just tested with it, we don't require https. Edit: And we don't use SSL.

MykonCodes avatar Mar 04 '18 12:03 MykonCodes

Have you tried a url at the root domain? e.g. like http://qnova.io:3000 I haven't personally figured out how to get the path option to work with servers (https://socket.io/docs/server-api/#new-server-httpserver-options) we might need a to handle path in a special way on connection like the javascript client does in the io([url],[options]) function (https://socket.io/docs/client-api/#io-url-options)

We'd could use a working minimal example of a server with path and javascript client with path to see what's missing in the c++ client.

getnamo avatar Mar 05 '18 12:03 getnamo

Sorry that I didn't respond, had some other issues to work on. And I was being stupid, sorry for that, we indeed use HTTPS. Now I am 99% sure I tested on non-https too, but maybe I had a typo or something, I don't know, at least non https URL's now work, but yeah.. Really need HTTPS to work. So I'll look into how to enable it.

MykonCodes avatar Mar 08 '18 08:03 MykonCodes

So I spend the whole day trying to get OpenSSL working, and it is a total pain in the ***. To get everything running for a x64 machine. Eventually I tried 5 different versions of socket io cpp, got OpenSSL integrated and UE4 starting up 2 times, but only to find out that now no IP or URL at all works anymore..

MykonCodes avatar Mar 08 '18 18:03 MykonCodes

My current run is using your prebuild repository, where I had to tweak a ton already to make CMake build with OpenSSL and find the proper boost libs, but yeah... When I bind the sioclient_tls.lib, it just doesn't work.. Spits out ITERATOR_DEBUG_LEVEL mismatches when I try to use the debug build, so I can't debug it either..

MykonCodes avatar Mar 08 '18 18:03 MykonCodes

It's awesome to have another pair of eyes on getting this set up. Getting everything to splice even for the regular non-ssl version was always a day affair for me and I'm frankly a noob at cmake. If you get a working build, consider making a pull request on prebuild and here.

Regarding TLS, Have you had a look at these two issues

https://github.com/socketio/socket.io-client-cpp/issues/13 and https://github.com/socketio/socket.io-client-cpp/issues/46?

First issue should point at code changes that were needed for TLS work with socket.io and issue 46 points to needing a macro define for things to compile. Other than that you can still run UE4 in debug mode while having release libraries linked which may hint at where the issue may lie even if the lib code is not all exposed.

getnamo avatar Mar 08 '18 19:03 getnamo

Got it working. It required a ton of cheat-arounds though and god do I hate CMake. Same goes for me, I know the basics of it but I want to vomit each time I have to use it :P

Had to change the CMakeList.txt, add a bunch of dll's, windows lib's, and even change some websocketpp code that just didnt wanted to compile (just an undefined enum, so I hardcoded the integer value in). Another PITA was x64 vs x86, as I couldnt get anything with x86 to run I had to figure out how to make CMake build x64 solutions.

I'll see if I can figure out a way to do a pull request, however I noticed that connections to normal HTTP servers don't work anymore with TLS enabled. I can share the code privatly with you first if you also want to have a look on how to use TLS only when applicable.

MykonCodes avatar Mar 08 '18 22:03 MykonCodes

I'd be definitely interested in the build configs changed for ssl and working prebuilt libraries (.lib). Even if it is a trade off atm it would get us closer to getting a full solution. What I've done is open a new branch called windows-ssl on the prebuild here https://github.com/getnamo/socketio-client-ue4/tree/windows-ssl and if you make a pull there we will have it for reference when trying to get a holistic solution.

getnamo avatar Mar 09 '18 01:03 getnamo

Alright, I will see if I can get anything useful together. Issue here is I have around 5-6 sioclient projects on my PC now and I think I even had to use a special version of the websocketpp repo. If I create a pull request I at least want it to be somewhat useable and approved, so it might take me a bit. Also, you created the branch on the plugin, not the prebuild. :)

MykonCodes avatar Mar 09 '18 14:03 MykonCodes

Whoops :)! here's the new branch https://github.com/getnamo/socketio-client-prebuild/tree/windows-ssl

Note that the pre-build uses submodules: https://github.com/getnamo/socketio-client-prebuild/tree/windows-ssl/src which then depends on submodules: https://github.com/getnamo/socket.io-client-cpp/tree/bfa0a53a4851cbbd56d4606c6d6fbed3f81a964b/lib so you can also add pull requests there to update the websocket library and it will all be contained :) (made a branch there too: https://github.com/getnamo/socket.io-client-cpp/tree/ssl-fixes)

getnamo avatar Mar 09 '18 17:03 getnamo

As I currently have a ton to do, for now I zipped up the socket io cpp folder with the cmake files and everything. https://www.dropbox.com/s/rukc165a0uj91m1/socket.io-client-cpp.zip?dl=0

I also had to make TLS to use the OpenSSL of UE4 (because otherwise there were multiple definitions of the crypto lib while packaging), so you will need to replace the reference to it in the sioclient_tls project. I think I only have the working settings in the configuration RelWithDebInfo x64.

And here the (messy) build.cs https://www.dropbox.com/s/vkknmklnuh37vaw/SocketIOClient.Build.cs?dl=0

btw the lib's I link in the build.cs are part Windows, (C:\Program Files (x86)\Windows Kits\10\Lib\10.0.15063.0\um\x86\User32.Lib etc)

MykonCodes avatar Mar 09 '18 21:03 MykonCodes

Hey, any updates on this?

AgrYpn1a avatar Sep 09 '18 18:09 AgrYpn1a

The issue lies at the underlying websocketpp library, which requires an update to support TLS and non TLS endpoints at the same time. Some movement has been made toward providing easy examples to support this here https://github.com/zaphoyd/websocketpp/issues/734 and here https://github.com/zaphoyd/websocketpp/issues/706

Once an example is available for reference in order to update https://github.com/socketio/socket.io-client-cpp we can merge that in when we recompile the library for this plugin's use.

Contributions are welcome!

getnamo avatar Sep 10 '18 05:09 getnamo

Okay, I followed links, and found this commit https://github.com/socketio/socket.io-client-cpp/pull/137. I managed to integrate it in socket.io and build the lib. How can I recompile your plugin in order to test if everything is working correctly?

--- This basically adds a new constructor that accepts url as parameter, then call connect() with no parameters to connect, and based on url it will determine whether to use https or http.

EDIT: Figured it out, should add those files directly to ue4 plugins/socketio-client-u4/Source. Trying to build now, will report later what happened.

UPDATE: Getting bunch of LINK errors, unresolved externals and mismatches after adding modified plugin lib and headers.

UPDATE2: Here's the error log https://gist.github.com/rastko1996/5ef59b8aaf6ee80cf27946534cdf8182

AgrYpn1a avatar Sep 10 '18 11:09 AgrYpn1a

Will take a peek at that when I have the time, maybe on saturday. It's been a while since I got it working and didn't touch it since.

MykonCodes avatar Sep 14 '18 12:09 MykonCodes

Why hasn't this been added to the main repo before this guys dropbox takes that script down??

ughstudios avatar May 24 '20 23:05 ughstudios