Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue-socket.io How to connect to multiple websocket servers

Tags:

vue.js

vuex

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?

like image 555
Nils Köhler Avatar asked Aug 07 '18 12:08

Nils Köhler


People also ask

Can you have multiple WebSocket connections?

At Stream, whenever you connect a user to a channel, you create a WebSocket connection. That means for every connected user, there's at least one connection open. But, did you know it's possible for a single user to connect multiple times? This is what we refer to as “concurrent connections”.

How many WebSocket connections can you have?

The theoretical limit is 65k connections per IP address but the actual limit is often more like 20k, so we use multiple addresses to connect 20k to each (50 * 20k = 1 mil). I then run the web server as root by typing sudo -i followed by ulimit -n 1024000 and then node examples/WebSocket. js (in the uWebSockets.

How many Socket connections can Socket.IO handle?

As we saw in the performance section of this article, a Socket.IO server can sustain 10,000 concurrent connections.

Can Socket.IO connect to WebSocket?

Although Socket.IO indeed uses WebSocket for transport when possible, it adds additional metadata to each packet. That is why a WebSocket client will not be able to successfully connect to a Socket.IO server, and a Socket.IO client will not be able to connect to a plain WebSocket server either.


1 Answers

You can find the solution on Github: https://github.com/MetinSeylan/Vue-Socket.io/pull/98

Adding multiple namespaces/socket connetions

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.

like image 50
Lazac92 Avatar answered Oct 13 '22 01:10

Lazac92