Skip to content

Instantly share code, notes, and snippets.

View bhaveshgohel's full-sized avatar
👨‍💻
I may be slow to respond.

Bhavesh Gohel bhaveshgohel

👨‍💻
I may be slow to respond.
View GitHub Profile
@bhaveshgohel
bhaveshgohel / chat-server.js
Created March 10, 2018 12:01 — forked from graphicbeacon/chat-server.js
A simple TCP chat server with NodeJS, based on the example provided by creationix.
var net = require('net');
var sockets = [];
var port = 8000;
var guestId = 0;
var server = net.createServer(function(socket) {
// Increment
guestId++;
socket.nickname = "Guest" + guestId;
@bhaveshgohel
bhaveshgohel / server.js
Created March 10, 2018 12:02 — forked from sadick254/server.js
A Simple TCP Chat Server In Node Js
//run this with 'node server.js' and then test in multiple computers using 'telnet 192.168.0.1 9000'
// replace '192.168.0.1' with your ip.
(function () {
'use strict';
let net = require('net');
let chatServer = net.createServer(),
clientList = []; // a list of connected clients/ machines
chatServer.on('connection', function (client) {
//once a client connects we add it to our clientList
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
const name = db.user && db.user.name;
const name = db.user?.name