Answers for "node js socket"

2

install socket.io

npm i socket.io
Posted by: Guest on October-03-2020
1

socket.io client send data node js server

var socket = io.connect('http://localhost');
socket.emit('my other event', { my: 'data' });
//server side
io.sockets.on('connection', function (socket) {
  socket.on('my other event', function (data) {
    console.log(data);
  });
});
//sending data from the user via a socket.io
socket.on("test", function (data) {
    data.forEach(obj => {
        console.log("Yer : " + obj.yer + ", Lat : " + obj.lat + ", Long : " + obj.lng);
    })
});
Posted by: Guest on November-28-2020
0

create a web server node js w socket.io

var app = require('express')();
var http = require('http').createServer(app);
var io = require('socket.io')(http);

app.get('/', (req, res) => {
  // Ran when a GET request to path '/'
  res.sendFile(__dirname + '/index.html');
});

io.on('connection', (socket) => {
  // Ran when a socket connected
});

http.listen(3000, () => {
  // Ran when server is ready to take requestes
});
Posted by: Guest on December-31-2020
3

socket..io

<script src="https://cdn.socket.io/socket.io-3.0.1.min.js"></script>
Posted by: Guest on November-24-2020
3

socket io

npm install --save socket.io
Posted by: Guest on December-01-2019
0

socket io node js

npm install socket.io
Posted by: Guest on December-02-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language