server sided code
const express = require('express')
const app = express()
const server = require('http').Server(app)
const io = require('socket.io')(server)
io.once('connection', function (socket) {
console.log(`New connection`)
socket.emit('hello', 'hello from the server')
socket.on('clientData', (data) => {
console.log(data)
})
})
server.listen(3000, () => {
console.log(`Server started: http://localhost:${port}`)
})
Client side code:
var socket = io()
var hello = 'Hello server'
socket.on('connection', function() {
console.log('established connection')
socket.emit('clientData', hello)
})
socket.on('hello', function(data) {
console.log(data)
})
When run the client doesnt emit the 'clientData' for some reason, what am I doing wrong.
via Satonamo
No comments:
Post a Comment