Reputation: 113
I try to connect to two different web-socket Servers from a VUE-Client with vue-socket.io like this:
import { store } from '@/store/store'
import { store2 } from '@/store/store2'
Vue.use(Vuex)
Vue.use(VueSocketio, 'http://192.168.1.101:8000', store)
Vue.use(VueSocketio, 'http://192.168.1.102:8001', store2)
I have created 2 store files store.js
and store2.js
Actually the first Vue.use(VueSocketio…
line will connect and work properly, but the second will not. So in the upper example Port 8000
connects but not Port 8001
. When I swap the two lines Port 8001
will connect but Port 8000
will not.
All Examples I found deal only with one Web-socket Server and that works fine. What is the best practice to connect to multiple Web-socket Servers with a VUE-Client?
Any idea how I get both connected?
Upvotes: 8
Views: 2959
Reputation: 145
You can find the solution on Github: https://github.com/MetinSeylan/Vue-Socket.io/pull/98
let connectObj = {
notification: 'http://localhost:5000/notification',
client: 'http://localhost:5000/client'
}
Vue.use(VueSocketio, connectObj, store)
This adds capability to listen to multiple socket instances (for ex- namespaces) in single Vue instance. If connection is passed as an object, the keys can be used to identify and thus will be able to isolate listeners.
Upvotes: 2