简体   繁体   中英

Ratchet WebSocket won't work over Vagrant machine

I have a WebSocket server using Ratchet (literally the example app). I'm serving it to localhost:8080 on my Vagrant machine (which is a CentOS 6) and trying to connect to it through the private network IP set in the Vagrantfile 192.168.33.10 .

I'm getting a connect ECONNREFUSED 192.168.33.10:8080 (the uri is ws://192.168.33.10:8080/chat ).

I already exposed the port config.vm.network "forwarded_port", guest: 8080, host: 8080 .

I've tried serving the server (inside vagrant) to localhost , 127.0.0.1 and 192.168.33.10 , but the client still can't connect.

It works fine outside of Vagrant using localhost on both client and server.

What am I missing?

If you bind the app to localhost there is no way you can access it via 192.168.33.10 , hence port forwarding won't work either.

You need to make your app to listen on 192.168.33.10:8080 .

Also add the guest's IP address to the Vagrantfile:

config.vm.network "forwarded_port", guest_ip: "192.168.33.10", guest: 8080, host: 8080

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM