Created
February 20, 2019 15:11
-
-
Save questsin/1e7e19f1787bd3a0e593181ee78a81d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load the net module to create a tcp server. | |
var net = require('net'); | |
// Creates a new TCP server. The handler argument is automatically set as a listener for the 'connection' event | |
var server = net.createServer(function (socket) { | |
// Every time someone connects, tell them hello and then close the connection. | |
console.log("Connection from " + socket.remoteAddress); | |
socket.end("Hello World\n"); | |
}); | |
// Fire up the server bound to port 7000 on localhost | |
server.listen(7000, "localhost"); | |
// Put a friendly message on the terminal | |
console.log("TCP server listening on port 7000 at localhost."); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment