question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot connect multiple socket

See original GitHub issue

The old method is not working anymore https://github.com/MetinSeylan/Vue-Socket.io/pull/98

Is there any update for multiple connections?

My code:

const VueSocketIO = require('vue-socket.io')
const connectObj = {
  notification: process.env.VUE_APP_NOTIFICATION_SOCKET_SERVER_ENDPOINT,
  backend: process.env.VUE_APP_SOCKET_SERVER_ENDPOINT
}

Vue.use(
  new VueSocketIO({
    debug: true,
    connection: connectObj,
    vuex: {
      store,
      actionPrefix: 'SOCKET_',
      mutationPrefix: 'SOCKET_'
    }
  })
)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
ghjackycommented, Oct 9, 2020

@stevetsim Just as below. It works for me.

import VueSocketIO from 'vue-socket.io'
import SocketIO from 'socket.io-client'

const ns1 = SocketIO('http://127.0.0.1/ns1', {
  autoConnect: false,
  useConnectionNamespace: true
})
Vue.use(new VueSocketIO({
  debug: false,
  connection: ns1,
  vuex: {},
  options: {
    useConnectionNamespace: true
  }
}))

const ns2 = SocketIO('http://127.0.0.1/ns2', {
  autoConnect: false,
  useConnectionNamespace: true
})
Vue.use(new VueSocketIO({
  debug: false,
  connection: ns2,
  vuex: {},
  options: {
    useConnectionNamespace: true
  }
}))

Then, in single component which using ns1 (ns2 is the same as ns1):

  data() {
    return {
      ws_path: '/server1/socket.io'
    }
  },
  created() {
    this.$socket['ns1'].io.opts.path = this.ws_path
    this.$socket['ns1'].open()
  },
  beforeDestroy() {
    this.$socket['ns1'].close()
  }

Open and keep the connection only if you need it. Just don’t forget to set the socket path before the connection opening every time.

0reactions
N3R00commented, Jun 18, 2022

Não funciona para mim… this.$socket[‘namespace’] é indefinido imagem

i have the same problem

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to connect with multiple client with my socket server ...
My socket server program is mentioned below. It works fine with the single client but when I try to connect it with another...
Read more >
Troubleshooting connection issues | Socket.IO
the socket is not able to connect; the socket gets disconnected; the socket is stuck in HTTP long-polling; other common gotchas. Problem: the ......
Read more >
Socket allocation problems cause operations to fail with error ...
After a socket is closed, the socket connection stays in a TIME_WAIT state for approximately two minutes more (the amount of time depends...
Read more >
Socket.Connect Method (System.Net.Sockets) | Microsoft Learn
This method is typically used immediately after a call to GetHostAddresses, which can return multiple IP addresses for a single host. If you...
Read more >
Socket Programming HOWTO — Python 3.11.1 documentation
Finally, the argument to listen tells the socket library that we want it to queue up as many as 5 connect requests (the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found