getnamo / SocketIOClient-Unreal

Socket.IO client plugin for the Unreal Engine.
Other
901 stars 240 forks source link

Cannot connect to SocketIO server #425

Open t0msk opened 6 months ago

t0msk commented 6 months ago

Hello,

I use Unreal Engine 5.3.2 on Linux, this is my Blueprint graph for connection:

image

TL;DR I have Persistent level where is SocketIO actor placed, so I can access it from everywhere, as you can see I just take ref from Persistent level, access SocketIO component and call Connect with params.

Problem is that my server doesn't register any connection, but when I use some SocketIO testing tool like: https://amritb.github.io/socketio-client-tool

and I set settings like: image

It will connect from that SocketIO testing tool, but not from UE, even when params are the same.

My SocketIO server is written in Rust, it looks like:

fn on_connect(socket: SocketRef, Data(data): Data<Value>) {
    info!("Socket.IO connected: {:?} {:?}", socket.ns(), socket.id);
    println!("Socket.IO connected: {:?} {:?}", socket.ns(), socket.id);
    socket.emit("auth", data).ok();

    socket.on(
        "message",
        |socket: SocketRef, Data::<Value>(data), Bin(bin)| {
            info!("Received event: {:?} {:?}", data, bin);
            println!("Received event: {:?} {:?}", data, bin);
            socket.bin(bin).emit("message-back", data).ok();
        },
    );

    socket.on(
        "message-with-ack",
        |Data::<Value>(data), ack: AckSender, Bin(bin)| {
            info!("Received event: {:?} {:?}", data, bin);
            println!("Received event: {:?} {:?}", data, bin);
            ack.bin(bin).send(data).ok();
        },
    );
}

    io.ns("/socket.io", on_connect);

    let app = axum::Router::new()
        .route("/", get(|| async { "Hello, World!" }))
        .route("/login", post(login))
        .layer(
            ServiceBuilder::new()
                .layer(CorsLayer::permissive()) // Enable CORS policy
                .layer(layer),
        );

For Rust I use this SocketIO server implementation: https://github.com/Totodore/socketioxide

getnamo commented 5 months ago

Do you disable auto-connect on component to ensure it connects with params instead at your bp call time?

t0msk commented 2 months ago

Sorry for late reply, but I was doing other stuff, so I would like to get back to this issue, I updated to UE 5.4 and newest SocketIO client and issue still persist, if I run my server, I can connect to it via SocketIO Online testing tool, but with same params I cannot connect via UE.

Yes auto connect is disabled in BP, so it tries to connect using params:

image

and these are working params in online testing tools:

image

### EDIT:

Okay I looked into my server logs and there is some connection happening:

2024-09-27T13:45:56.733059Z DEBUG on_connect{sid="jIEFGFl3IX8DFP_d"}: socketioxide::client: 161: eio socket connect
2024-09-27T13:45:56.733095Z DEBUG on_connect{sid="jIEFGFl3IX8DFP_d"}: socketioxide::client: 97: spawning connect timeout task
2024-09-27T13:45:56.733138Z DEBUG engineioxide::transport::ws: 133: [sid=jIEFGFl3IX8DFP_d] new websocket connection
2024-09-27T13:45:56.733273Z DEBUG socketioxide::client: 205: Received message: "0{}"
2024-09-27T13:45:56.733287Z DEBUG socketioxide::client: 216: Packet: Packet { inner: Connect(Some("{}")), ns: "/" }
2024-09-27T13:45:56.733297Z DEBUG socketioxide::client: 47: auth: Some("{}")
Socket.IO connected: "/" jIEFGFl3IX8DFP_d
2024-09-27T13:45:56.741352Z DEBUG on_connect{sid="YfBM4EQMkJ6g7zQf"}: socketioxide::client: 161: eio socket connect
2024-09-27T13:45:56.741381Z DEBUG on_connect{sid="YfBM4EQMkJ6g7zQf"}: socketioxide::client: 97: spawning connect timeout task
2024-09-27T13:45:56.741429Z DEBUG engineioxide::transport::ws: 133: [sid=YfBM4EQMkJ6g7zQf] new websocket connection
2024-09-27T13:45:56.741565Z DEBUG socketioxide::client: 205: Received message: "0{}"
2024-09-27T13:45:56.741582Z DEBUG socketioxide::client: 216: Packet: Packet { inner: Connect(Some("{}")), ns: "/" }
2024-09-27T13:45:56.741595Z DEBUG socketioxide::client: 47: auth: Some("{}")
Socket.IO connected: "/" YfBM4EQMkJ6g7zQf

but when I do branch in UE while checking "is connected" I always get false:

image

t0msk commented 2 months ago

Problem was that path was "/socket.io" instead of "socket.io", looks like its working now.

But there is still issue that after connection I get in that branch "no connected condition", why?

EDIT: but when I listen on "Connected" event it will fire and I will get all information like session ID.