Permalink
Browse files

[examples] Fixing things up, more debug

  • Loading branch information...
Jonas Pfenniger
Jonas Pfenniger committed Dec 27, 2009
1 parent ac6acd4 commit 18be4a58f74a7b8bec0c2a1cba8dbcd23cd9b93b
Showing with 10 additions and 7 deletions.
  1. +1 −1 example/ping.js
  2. +5 −2 example/public/sample.html
  3. +4 −4 example/shared.js
View
@@ -19,7 +19,7 @@ function ping(msg, conn) {
function handler(req, res) {
sys.debug(req.method + ' ' + req.uri.path);
if (ws.askUpgrade(req)) {
- sys.debug("Upgrading to WebSocket");
+ sys.debug("Upgrading to WebSocket " + req.headers.cookie);
var conn = new ws.Connection(req, res);
conn.addListener("message", ping);
conn.addListener("close", function() {
@@ -26,14 +26,17 @@
ws = new WebSocket("ws://localhost:8000/echo");
// Set event handlers.
- ws.onopen = function() {
+ ws.onopen = function(e) {
+ if (console) console.log("open", e);
output("onopen");
};
ws.onmessage = function(e) {
+ if (console) console.log("message", e);
// e.data contains received string.
output("onmessage: " + e.data);
};
- ws.onclose = function() {
+ ws.onclose = function(e) {
+ if (console) console.log("open", e);
output("onclose");
};
View
@@ -13,8 +13,8 @@ const mimeMap = {
function notFound(req, res) {
var msg = "<h1>File not found : " + req.uri.path + "</h1>";
res.sendHeader(404, {
- "Content-Type": "text/html",
- "Content-Length": msg.length
+ "Content-Type": "text/html",
+ "Content-Length": msg.length
});
res.sendBody(msg);
res.finish();
@@ -24,8 +24,8 @@ function sendFile(req, res, path) {
posix.cat(path, "binary").addCallback(function(data) {
var cType = mimeMap[mimeReg.exec(path)[0]] || "application/octet-stream";
res.sendHeader(200, {
- "Content-Length": data.length,
- "Content-Type": cType
+ "Content-Type": cType,
+ "Content-Length": data.length
});
res.sendBody(data, "binary");
res.finish();

0 comments on commit 18be4a5

Please sign in to comment.