Giter VIP home page Giter VIP logo

Comments (1)

gongzili456 avatar gongzili456 commented on May 23, 2024

@luo7023539 您好,感谢您使用并提出疑问。经过我的测试逗号的事情只是显示的问题,并不影响数据的解析。Server 端使用 socket.io 不需要任何特殊处理。一切正常请放心使用。
我的测试代码如下:

Codes

server.js

const chat = io.of('/chat').on('connection', socket => {
  console.log('--> ', 'ns-chat: comming')

  socket.on('hi', d => {
    console.log('hi from client: ', d)
  })

  socket.emit('a message', {
    that: 'only',
    '/chat': 'will get',
  })
  chat.emit('a message', {
    everyone: 'in',
    '/chat': 'will get',
  })
})

const news = io.of('/news').on('connection', function(socket) {
  console.log('--> ', 'ns-news: comming')

  socket.on('woot', d => console.log('woot from client: ', d))
  socket.emit('item', { news: 'item' })
})

weapp-client.js

    const chat = io('http://localhost:3000/chat')
    const news = io('http://localhost:3000/news')

    chat.on('a message', function(d) {
      console.log('chat got: ', d)

      chat.emit('hi', 'hi server')
    })

    news.on('item', function(d) {
      console.log('news got: ', d)
      news.emit('woot', { woot: 'server' })
    })

Results:

server side:

-->  ns-chat: comming
-->  ns-news: comming
hi from client:  hi server
hi from client:  hi server
woot from client:  { woot: 'server' }

client side:

chat got:  {that: "only", /chat: "will get"}
chat got:  {everyone: "in", /chat: "will get"}
news got:  {news: "item"}

from weapp.socket.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.