[Plugin] Socket.io Client

From a quick scan of the feature, it appears to be server based.

Follow e.g. psitsmike.com - psitsmike Resources and Information. and node.js - Dynamic rooms in Socket.io - Stack Overflow to implement it on the server. On the client you’d only need an emit call to switch to the new room and the server handles the switch, in the stack overflow answer the server then emits a message back to the client to do any room update logic (in that example ‘updaterooms’).

Good day, it’s mean on server side i wrote emit logic for connect new room and than “On Event” i can get message from server?

I already try to emit connect to room, but i try send data into room from web-page to unreal with “On Event” and it’s not work.

Did you bind your event so that it can be seen by ‘On Event’? see https://github.com//socketio-client-ue4#how-to-use---bp-basics

Sorry for delay. Already found troubles, it’s my missed. I have question: why after connection stoped and server start again unreal can’t connect to server.

You’ll have to be more specifc with the details of what you’re doing, describe it step by step. The plugin does automatically reconnect to servers if you stop them and restart them. There may be ~5-25 second delay before the connection is re-established depending on how long you’ve been disconnected though (you can change reconnection settings directly on the socketio client component).

  • thanks a million for this plugin. Diving into it now. I’m really interested in using it to communicate with an IRC server to send and retrieve messages. I’m having trouble figuring how how to begin this using your plug-in. I have a web interface setup (KiwiIRC) connected to a IRC network, but I’m having trouble figuring out how to send login info (nickname) to the web interface from your plugin. Could you share any insight? Thanks so much.

This plugin connects unreal as a client of a socket.io server, so the best way to setup what you’re looking for is to have a socket.io server in say node.js or python which does API calls to your other service (IRC) and forwards them to the unreal clients. (the plugin does support general http requests, but it’s not recommended for real-time push services as you’d lose the bidirectionality and ease of use)

E.g. if you used a node.js server, you could probably use this npm package irc - npm, and then pipe the sent/received messages to your client via your desired events

just browsing the package, forwarding a message would be something like



client.addListener('message', function (from, to, message) {
    socket.emit('chat message', from + ' => ' + to + ': ' + message);
});

(see https://github.com//socketio-…erver/index.js for a node.js server hosting a basic chat client, socket.on are events that the server receives, socket.emit (or io.emit for multicast) are server send functions)

https://github.com//socketio-client-ue4-example is a good starting point to understand typical server and client side setup with full sources.

First,it’s awsome.But as a new learner,I got some questions.
if I want to use the server to connect to mysql ,how could I use variables in ue4 as parametres to execute sql query?
thanks a lot.

I’d probably form my query as a blueprint struct with desired parameters, then use the Struct to Json Object to convert it to a json object and emit that to your server. From there you can use the json object to form your sql query. See https://github.com//socketio-client-ue4#structs for details on how to formulate complex json objects using structs.

Hey there,

I´m trying to store some profilepictures with a nodejs socket.io server into a mongodb database.
I tried a lot of stuff but unfortunately I can´t get it workin’.

I attached 3 screenshots.
One from inside of UE,
one of the saved “<Binary Data>” inside the mongo db database…
and the last one shows the “<Binary Data>” printed from the nodejs server after getting it from the datatable…
But when I get the binary data within unreal it´s emtpy… Is this any known bug? - or am I doing anything wrong?

Thanks in advance for any help <3!

I just checked the latest version of the plugin against a binary roundtrip test and it still works as expected. I don’t see your node.js logic in the pictures, without that I can only make assumptions. It looks like you’re trying to get the field ‘avatar’ when your json has the binary data under ‘useravatar’ so it could be getting the wrong field which is why it would be empty… Otherwise the blueprints look correct at a glance. You might consider using *emitWithCallback *if you’re trying to fetch some information from the server which would obviate the need to bind and emit another event for receiving the data.

I am running into big issues and I do not know how to solve it.

My UE 4.22 (UE 4.22-Oculus build from source) project, using the latest version of this plugin, running in Mac, disconnects the socket unexpectedly and is then no longer able to reconnect properly. I’m using manual connect and I’m not using a Plugin Scoped connection. Basically my projects send approx. 10 messages per ‘tick’. With a slow tick internal, like one tick every second, it’s stable and there are no problems. When I have the tick interbal on 0.1 second (so approx. 100 messages per second) it soon disconnects and cannot reconnect again. I see this in the log:


SocketIOLog: SocketIO eKjVnNjoMd2x6eRHAAAB appears to have lost connection, reconnecting attempt 0 with delay 5000

It then looks like it is rebuilding the connection. First to the default namespace and then to the namespace I was using. And the I get the same message ‘lost connection’ message again.

First of all I’m worried about the initial disconnect and the consecutive disconnects (after reconnect).

I’m using a node.js server with socket.io version 2.2.0.

Any ideas why this is happening?

What’s the C++ Socket IO client version that is being used? There may be a version mismatch. I have seen some reports about socket.io that indicate that you should make sure version is on par with server version.

Any help is appreciated.

Hi,

anybody can give me a hint how to get dynamic “rooms” for clients to join? (via room-ids)
Server-Side its something like this:


// attach Socket.io to our HTTP server
io = socketio.listen(server);

// handle incoming connections from clients
io.sockets.on('connection', function(socket) {
    // once a client has connected, we expect to get a ping from them saying what room they want to join
    socket.on('room', function(room) {
        socket.join(room);
    });
});

// now, it's easy to send a message to just the clients in a given room
room = "abc123";
io.sockets.in(room).emit('message', 'what is going on, party people?');

// this message will NOT go to the client defined above
io.sockets.in('foobar').emit('message', 'anyone in this room yet?');

but how to do the client-side via Blueprints?
Client-Side:



 // set-up a connection between the client and the server
var socket = io.connect();  
// let's assume that the client page, once rendered, knows what room it wants to join
var room = "abc123";  
socket.on('connect', function() {    
// Connected, let's sign-up for to receive messages for this room    
socket.emit('room', room); });  
socket.on('message', function(data) {    
console.log('Incoming message:', data); }); 

Thanks in advance for help :slight_smile:

Is it possible just to use this for JSON-RPC calls, or its not really in scope of this plugin?

Hey,

I got your Android supported release, for 4.22, and built for 4.20. It doesn’t want to connect from my phone though… I put the address and port as , it works when I play in the viewport but not when I build to my phone. It’s connected to the same Internet etc. Is there anything extra that I need to do?

Running into Errors everytime I start the Project, the Socket.io Actor Component is undefined, and thus breaks all blueprint notes and routes. And idk why. Anyone had this happen too them?

This is likely related to https://github.com//socketio-client-ue4/issues/126, I’m still looking into the root cause of this, it seems to only affect the latest (v1.0), but versions earlier than that don’t support Mac.

What’s interesting is that you’re able to disconnect it by sending ~100 messages/sec which definitely shouldn’t happen. I’ve added a new issue for this bug: https://github.com//socketio-client-ue4/issues/135 and I’ll try to replicate it as well.

It may be a bit of time before I get to the bottom of these two. Thanks for the detailed issue descriptions!

It looks like you just connect and emit to the ‘room’ event name with ‘abc123’ room string id.

The equivalent in blueprints is
https://camo.githubusercontent.com/8a717ed3d46ba6b51912051c73ed42c68b18ff0a/687474703a2f2f692e696d6775722e636f6d2f6e69684d53507a2e706e67

but with the changed event names/message value.

Also in your begin play you’d bind to the event ‘message’

https://camo.githubusercontent.com/eab6a40ab7c42e3f788ba45b36d879856ebf68b9/687474703a2f2f692e696d6775722e636f6d2f645778436d76512e706e67

Full documentation is available at

https://github.com//socketio-client-ue4#how-to-use---bp-basics

If you mean using the socket.io protocol to do JSON-RPC calls, this is supported since both ends can understand and parse json.

You can use e.g. https://github.com//socketio-client-ue4#emit-with-callback and emit and receive calls, the server can use this passed in callback to remotely callback https://github.com//socketio-client-ue4#emit-with-callback-nodejs-server-example. You’d only need to make sure you follow jsonrpc spec (JSON-RPC 2.0 Specification) in your communication.

If you meant doing basic JSON http requests, this is supported albeit not the main focus of the plugin. I’ve added an example for a JSON http post request https://github.com//socketio-client-ue4/blob/master/README.md#http-json-requests.