NGROK - Custom events aren't triggering (related to SSL)
GiganticCo opened this issue · 18 comments
onConnected, onDisconnected etc etc trigger as expected. However, binding to a custom event via blueprints doesn't appear to work (I'm guessing it's the bind operation that's failing rather than the event firing failing ?).
I looked at the example and it's using a custom version of the plug-in with different functions.
I've also verified these same events on other platforms and they are fine (non-UE4).
Edit: Correction, it appears it fires the event once and once only.
Fantastic plug-in BTW (if I can get a solution to this).
As an update to this, two things;
-
If I emit a tick from UE4 and then emit any event from the server I want to catch, it'll work.
-
To catch the events sent from the server, I have to use Bind Event to Function. The On method doesn't ever get triggered. (Note: This relies on (1) to work continuously).
Have you updated the plugin to the latest version (0.4.0 - https://github.com/getnamo/socketio-client-ue4/releases/tag/0.4.0)? If so can you give me an example of your custom events? (screenshots)
Here you go.
Basically, two events I listen to, one that "updateCam" and one "test" (I thought it may have been case sensitive so I tried both events). The test event is basically just calling the echo example as a debugging aide.
You'll notice the "emit", without this, I receive the events one time only (which is upon first connection). On the server, I emit those events either when a connection is first established AND when an onTick event is received (which is what is keeping UE4 going).
And just to clarify, the events are never received via the On callback approach.
Just to clarify server side in this example;
socketio.on("connection", function(socket) { socketio.emit("test", { text: "Hi!" } ); socketio.emit("updateCam", { text: "Hi!" } ); socketio.on("onTick", function(data) { socketio.emit("updateCam", { text: "Ticked" } ); }); }
Sorry, GitHub isn't formatting that code block very well. It's basically emitting two events on the server upon connection and then, every onTick event received echoing back another event.
Feel free to DM me on Twitter (I just followed you). I can trigger these events on my server and give you temp access to the URL. If it helps debug, I was going to debug myself later anyway. Cheers.
are you trying to receive these events as the 'On' event or through a custom bp function? the syntax is different for both of those cases.
If you want to receive it in the general 'On' event from the component you set it up this way (note it says Bind Event only):
and then you can compare the event string in the 'On' event to filter your events.
on the other hand if you want to bind the event to a custom function you use the Bind Event To Function
and you setup your custom bp function this way:
Note that in the second method you do not need to filter the event further. Encode json is also completely optional but a good way to see what kind of response you got.
I hope that clears up the flow, let me know if that still doesn't resolve it.
Actually, that exactly what I did. As I said, the only way I could get to even stay alive was to emit an event to the server and have it generate the events otherwise the UE4 end never gets the events via On or Bind.
Just to clarify, I'm getting the events 100% now, via BindToEvent, but, only if on the UE4 side I am continuously emitting a Tick to the server.
Also, to clarify, I was never able to get events via On to trigger. (OnConnected worked fine however).
It may be an issue with your server code.
The general structure of socket.io code is like this:
var io = require('socket.io').listen(3000);
io.on('connection', function(socket){
//track connected clients via log
console.log('connected: ' + socket.id);
//track disconnected clients via log
socket.on('disconnect', function(){
console.log('disconnected: ' + socket.id);
});
//Custom event - echo what we receive
socket.on('echo', function(message){
console.log('echo request received: ' + message);
socket.emit(message);
});
});
if you want to also support the web you typically do something like this (dependency on express)
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
//Send your web client index.html here
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
//track connected clients via log
console.log('connected: ' + socket.id);
//track disconnected clients via log
socket.on('disconnect', function(){
console.log('disconnected: ' + socket.id);
});
//Custom event - echo what we receive
socket.on('echo', function(message){
console.log('echo request received: ' + message);
socket.emit(message);
});
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
Notice that once you connect to a socket you need make events on the server for that socket, not for socket.io in general.
I'm going to make an example from scratch to see if I can replicate your bug though.
Thanks. The server code I gave was a snippet to show what was working, I have another non UE4 client (iOS) and it's receiving the events on the same socket. (I can replicate this on multiple endpoints / sockets too).
Basically my server code looks like the example you posted
Thanks for taking a look :)
btw what version of socket.io is the server running on?
Latest release for everything (I was grasping when looking into this). If it helps replicate I used ngrok for exposing the server. Perhaps it's when it drops to a long poll connection ? Not sure. As I said, iOS is receiving the events no problem without the emit.
I do wonder if ngrok might be the issue here. So far I haven't found a case where the events aren't behaving as expected, but I've always connected directly to either localhost or external server exposing a port directly. Do you have the ability to test this on localhost or direct port exposed to the internet?
I can test this however, if ngrok was the culprit this would mean my iOS client wouldn't receive those same events, which it is. I do know the iOS framework for socket.io handles dropping down to http long polling no problem so perhaps the UE4 plugin doesn't auto establish the connection if it drops and therefore isn't get the events ?
This would certainly explain why the events work if I constantly emit an event from the UE4 end essentially keeping the connection alive ?
the ue4 version is based on socket.io c++ client which largely depends on websockets, it may very well be that the underlying library can't handle downgrading, but that would require understanding how https://github.com/socketio/socket.io-client-cpp works on a deeper level. Are there any examples based on that library that you could try?
just realized that the original socket.io cpp client was compiled without OpenSSL, this may be why ngrok tunneling was failing. If this is the issue, the socket.io cpp static libs would need to be recompiled with opensll included to enable this behavior.
closing due to likely duplicate of openssl issue