Created
September 27, 2012 17:17
-
-
Save andrewrk/3795226 to your computer and use it in GitHub Desktop.
node.js / express socket problem
This file contains 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
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"); | |
}); |
This file contains 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
$ node -v | |
v0.8.10 | |
$ node server.js | |
listening on 13116 | |
Got here |
This file contains 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
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); |
This file contains 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
$ 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