Socket.io Server Listening in Vue Components

199 views Asked by At

I have a socket.io server :

  const http = require('http').createServer();
    
    const io = require('socket.io')(http, {
        cors: { origin: "*" }
    });
    
    io.on('connection', (socket) => {
        console.log('a user connected');
    
        socket.on('message', (message) =>     {
            console.log(message);
            io.emit('message', `${socket.id.substr(0,2)} said ${message}` );   
        });
    });
    
    http.listen(8080, () => console.log('listening on http://localhost:8080') );

And I am using Vue 3. I want to listening come from server side. An than I will try to show this message in vue components. But I couldn't do that. I installed socket.io and vue-socket.io library. But I couldn't import of socket.io in Vue component. How can I do that?

0

There are 0 answers