[Plugin] Socket.io Client

it deosn’t work with me and i don’t know whats is wrong ! i did everything like the tutorial and it just didnt work , any help ?

I want to execute a basic url call with static void CallURL() function. Where do i have to connect the delegate pointer in blueprint which is called by reference?

Hey guys i have a question. For example i have different channels in SocketIO like CHannel 1 Channel 2 etc. is it possible to connect to different channels with this plugin? If so then let me please know where to find this function

Thanks

The plugin supports socket.io namespaces. When you send a message or bind an event you specify the namespace which by default is just ‘/’. Changing that to your namespaces should do what you’re trying to achieve. See https://github.com//socketio-client-ue4 readme for full documentation.

Now also available on the marketplace for free: Socket.IO Client in Code Plugins - UE Marketplace. Currently available for 4.19, Marketplace 4.20 build pending.

Anybody on here who can possibly answer a question about why i only get “SIOJsonValue” printed to screen when my message from the server says something different?
I basically just want to get the server message printing correctly into Unreal and then be able to access the X: value and the Y:value in the message. I’ve added images below to show my setup.

this is how i am binding the event:

server-message-being-sent-out.jpg

This is how i am just trying to print the message to screen and log:

server-message-being-sent-out.jpg

This is the output that unreal is displaying:

unreal-message-being-received.jpg

This is the message that my server is sending out:

server-message-being-sent-out.jpg

I assume the problem is the “get display name” function. Apologies if this is a really simple obvious question, but any pointers as to the problem and how to isolate the X and Y values from the message would really help me out.

Thanks,

Get Display Name is a built in function in the unreal engine which prints the UObjects name. What you’re looking for is Encode Json or AsString(SIOJsonValue), details about this behavior is documented here: https://github.com//socketio-…ing-json-value

Regarding decoding responses beyond debug printing I encourage you to read this section in the documentation readme: https://github.com//socketio-…ding-responses. In general the most efficient way to encode/decode values from server is to have Json Object value e.g. {“x”:5, “y”:6"} on the server side and build a custom c++ or blueprint struct that matches that format, then use the As Object and Json Object to Struct calls with a member variable of your struct type passed in. After that call has been made your member variable will be filled with the received values.

That’s great. Thanks for the fast response. I think i need to assess how i send these messages in, but for now i can use a simple split function to isoltae the correct part of the message. Thanks.

Welcome. Keep in mind that you’ll get most mileage out of the plugin by using Json Objects. You don’t necessarily need structs, but if you do something as simple as



//in your server code where you send your data

//make a temp object
var responseObject = {}

//fill fields
responseObject.x = 3;
responseObject.y = 5;

//emit the response
socket.emit('test5', responseObject);


It will allow you to decode your data very easily via either manual bp graphs

https://i.imgur.com/DuMs3Hu.png

or auto-struct fills

https://i.imgur.com/yWbJxbf.png

Leading to consistent decoding behavior. NB: In both examples *ResponseXY *is a Vector2D struct type provided by the engine. Since we passed in a json object with an ‘x’ and a ‘y’ property on it, these match the names of the struct properties of a *Vector2D *and will correctly fill when using the Json Object to Struct conversion.

Thank you for posting the example. I’ll try it the way you suggest. Many many thanks!

So i followed the advice to use the code in my server and it works great. BUT. How can i get the actual value that is being sent for x and y? I tried

var responseObject = {}
responseObject.x = responseObject.value;
responseObject.y = responseObject.value;

But this just returns an “Undefined” value for x and y. Thank you if you can help!

That’s a javascript question consider revising documentation here: JavaScript Tutorial.

To answer your problem, this largely will depend on how you have your values captured and encoded. Find what sends your x and y, store them in a var (or optimally bypass this step), and set those vars to responseObject.x.

The specific reason you’re getting undefined here is because you’ve created a javascript object via


var responseObject = {}

and then you try to set it’s .x property value to the contents of it’s .value property, but this hasn’t been defined before that line.

Hello. I’m new to this wonderful plugin, so I’d like to know if it’s suitable for my needs.
I have two apps (one UE4/HTML5 and the other written in WebGL) on my webserver and I want them to communicate. I don’t think they can communicate directly, (correct me if I’m wrong), but they can indirectly by a common interface.
As far as I understood, my idea is to run a NodeJs server as the one provided in the example Chat project, with the feature to act as a bridge between the two apps.
Every time one app sends a message to this server, it automatically send it to the other app, and viceversa.
My questions:

  • is it possible to do that with this plugin?
  • if yes, is this considered a good solution of does exists even a better solution?

Thank you.

How you connect after you deploy the app I have been trying I change the URL for the deployed on with the port and is not connecting do you have any idea why? Im using https://socket-chat-example-bawzpjpxoy.now.sh/:433

I’m not aware of any UE4 code plugin working with HTML5. If there is documentation on how to get that working I’d be interested to see it. The plugin so far supports Windows and Linux platforms, but it’s open source so if any contributors get something working, consider making a pull request and I’ll include it.

Your best bet at this time would probably to use inbuilt UE4 get/post html commands.

​​​​​​https isn’t currently supported (use http) due to a bug in the underlying library which requires OpenSSL to be compiled in and use two different paths based on endpoints. Issue is currently tracked here https://github.com//socketio-client-ue4/issues/39

Hello,

I’m trying to implement this plugin with a python server also using socketio. I’m able to connect to the server and emit a message but when a try to receive from the server, UE keep crashing.

I haven’t been able to find a solution to my problem.

console_result.JPG

**Error in UE editor **: Error_socketio_project.JPG

Log file

As I understand it, I couldn’t bind an event. I couldn’t find why…

Here is my server code (python 3.7)


from aiohttp import web
import socketio
from colorama import init, Fore
init(autoreset=True)

sio = socketio.AsyncServer()
app = web.Application()
sio.attach(app)
#sio.manager.set_server


async def index(request):
   with open('index.html') as f:
     return web.Response(text=f.read(), content_type='text/html')

@sio.on('connect', namespace="/")
def connect(sid, env):
    print(Fore.RED + "connect ", sid)

@sio.on('test', namespace="/")
async def message(sid, data):
    print(Fore.GREEN + "message << ", data)
    await sio.emit('reply', "Hi i'm the server", sid)

@sio.on('disconnect', namespace="/")
def disconnect(sid):
    print(Fore.RED + 'disconnect', sid)

#app.router.add_static('/static', 'static')
app.router.add_get('/', index)


if __name__ == '__main__':
    web.run_app(app)


**Blueprints

**

Does anyone have an idea on how to solve this?

Thank you,

It looks like your reply is an array (“Hi i’m the server”, sid])


await sio.emit('reply', "Hi i'm the server", sid)

out of curiosity does it crash if you remove the last variable?


await sio.emit('reply', "Hi i'm the server")

have you tried embedding the sid response in an array? e.g.


await sio.emit('reply', "Hi i'm the server", str(sid]))

It may be that the function AsString is failing in detecting array SIOJsonValues. I’ve opened an issue on the plugin here: https://github.com//socketio-client-ue4/issues/102 for this problem, feel free to continue the discussion there.

Hi, this plugin need some any extra install?
Installed from marketplace, tryed the client sample, but not connetcting to server, don’t get any error.
Tryed from pc and android too. The server is run by another phone (work because can connect, send data with another client app).
Ip and port is good.
Created exe, added to firewall exception, still not work.
Packaged to android phone (android 7), not connect to the server.
4.20.3 UE version.

Any idea?

Android is not yet supported, only windows and linux. Also make sure you’re using http not https. See https://github.com//socketio-client-ue4-example for example documentation.

Good day, how i can connect to dynamicly created room, can you explain?