Answers for "socket.io"

2

install socket.io

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

socket

import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                break
            conn.sendall(data)
Posted by: Guest on September-17-2020
0

socket.io

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

app.get('/', function(req, res) {
   res.sendfile('index.html');
});

let clients = 0;
io.on('connection', function(socket) {
   clients++;
   io.sockets.emit('broadcast',{ description: clients + ' clients connected!'});
   socket.on('disconnect', function () {
      clients--;
      io.sockets.emit('broadcast',{ description: clients + ' clients connected!'});
   });
});

http.listen(3000, function() {
   console.log('listening on localhost:3000');
});
Posted by: Guest on June-28-2021
0

socket.io

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

socket.io

$ npm install socket.io
Posted by: Guest on August-25-2021
0

socket.io

var app = require('express')();
var http = require('http').Server(app);

app.get('/', function(req, res) {
   res.sendFile('index.html');
});

http.listen(3000, function() {
   console.log('listening on *:3000');
});
Posted by: Guest on June-25-2021

Browse Popular Code Answers by Language