Skip to content

Commit

Permalink
updated tcp examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mjurincic committed May 15, 2015
1 parent 55541b2 commit 7723921
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 17 additions & 0 deletions tcp/echo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.");
15 changes: 10 additions & 5 deletions tcp/server-echo.js → tcp/proxy-echo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
//https://gir.me.uk/simple-node-js-tcp-proxy/
/*jshint node:true*/
'use strict';

var net = require('net');

var proxyPort = 9020;
Expand Down Expand Up @@ -44,4 +40,13 @@ var server = net.createServer(function (socket) {
socket.on('error', function (err) {
console.log('Error: ' + err.soString());
});
});
});


server.listen(tcpServerPort);
proxy.listen(proxyPort);

console.log('Server Listening on ' + tcpServerPort +', Proxy Listening on ' + proxyPort);

// telnet localhost 9030
// telnet localhost 9020
Empty file removed tcp/proxy.js
Empty file.

0 comments on commit 7723921

Please sign in to comment.