install socket.io
npm i socket.io
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);
})
});
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
});
socket..io
<script src="https://cdn.socket.io/socket.io-3.0.1.min.js"></script>
socket io node js
npm install socket.io
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us