Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Created September 27, 2012 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewrk/3795226 to your computer and use it in GitHub Desktop.
Save andrewrk/3795226 to your computer and use it in GitHub Desktop.
node.js / express socket problem
var express, app;
express = require("express");
app = express();
app.configure(function() {
app.use(express.bodyParser())
app.use(app.router)
});
app.post('/up', function(req, resp) {
console.log("Got here");
resp.json({yay: "it worked"});
});
app.listen(13116, function() {
console.log("listening on 13116");
});
$ node -v
v0.8.10
$ node server.js
listening on 13116
Got here
var net, fs, read_stream, client, response_data;
net = require("net");
fs = require("fs");
read_stream = fs.createReadStream("smallfile.request");
client = net.connect(13116);
response_data = "";
client.on('data', function(data){
response_data += data;
});
client.on('end', function(){
var response_text, resp;
if (response_data.length === 0) {
throw new Error("wtf, it happened.");
}
console.log("it worked", response_data);
});
read_stream.pipe(client);
$ node -v
v0.8.10
$ node test.js
test.js:16
throw new Error("wtf, it happened.");
^
Error: wtf, it happened.
at Socket.<anonymous> (test.js:16:11)
at Socket.EventEmitter.emit (events.js:123:20)
at TCP.onread (net.js:417:51)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment