Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect to SocketIO server #425

Open
t0msk opened this issue May 31, 2024 · 3 comments
Open

Cannot connect to SocketIO server #425

t0msk opened this issue May 31, 2024 · 3 comments

Comments

@t0msk
Copy link

t0msk commented May 31, 2024

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
Copy link
Owner

getnamo commented Jun 4, 2024

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

@t0msk
Copy link
Author

t0msk commented Sep 27, 2024

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
Copy link
Author

t0msk commented Sep 27, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants