Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b41013b
commit d9fde60
Showing
3 changed files
with
176 additions
and
81 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,81 @@ | ||
<html> | ||
<head> | ||
<style> body { padding: 3em; } </style> | ||
<script src=jquery.js></script> | ||
</head> | ||
<body> | ||
<h1>node-jsond test page</h1> | ||
|
||
Send: <input onchange="changed(this.value)"><p> | ||
Rcvd: <textarea id=rcvd></textarea><p> | ||
|
||
<script src=jsonc.js></script> | ||
|
||
<h1>Test Page</h1> | ||
|
||
<b>Enter message values here</b><br> | ||
Construct a message by entering the key/value pairs in this box, one per line. | ||
<textarea id=vals cols=80 rows=8> | ||
m hello! | ||
</textarea> | ||
<input id=sendbtn type=button value="Send"><p> | ||
|
||
<b>This is the message actually sent to server</b><br> | ||
<textarea id=msgsent cols=80 rows=8></textarea> <p> | ||
|
||
<b>This is the response message from the server</b><br> | ||
<textarea id=msgrcvd cols=80 rows=8></textarea><p> | ||
|
||
|
||
|
||
<script> | ||
|
||
var rcvd = document.getElementById("rcvd") | ||
|
||
jsond.opts({port: 30304}) | ||
apiURL = "http://localhost:50505/api/" | ||
|
||
function el(id) { return document.getElementById(id) } | ||
function o2j(o) { return JSON.stringify(o) } | ||
function j2o(j) { return JSON.parse(j) } | ||
|
||
|
||
function jsondReady() { | ||
|
||
function changed(v) { | ||
var msg = {m:v} | ||
jsond.send(msg, function(response) { | ||
rcvd.value = "Response: "+JSON.stringify(response); | ||
|
||
var vals = el("vals") | ||
var msgrcvd = el("msgrcvd") | ||
var msgsent = el("msgsent") | ||
var seq = 1; | ||
|
||
$("#sendbtn").click(function() { | ||
var lines = vals.value.split("\n"), | ||
msg = {}, | ||
line, i, m | ||
|
||
msgrcvd.value = "" | ||
msgsent.value = "" | ||
|
||
for(i = 0; i < lines.length; i++) { | ||
line = lines[i] | ||
m = line.match(/^([^\s]+) (.*)$/) | ||
if(m) { | ||
msg[m[1]] = m[2] | ||
} | ||
} | ||
msgsent.value = o2j(msg) | ||
|
||
jsond.send(msg, function(rmsg) { | ||
msgrcvd.value = o2j(rmsg) | ||
}) | ||
}) | ||
|
||
} | ||
|
||
|
||
function docReady() { | ||
var d = document, e = d.createElement('script') | ||
e.id = "jsond" | ||
e.async = false | ||
e.src = apiURL | ||
e.onload = jsondReady | ||
d.body.appendChild(e) | ||
} | ||
|
||
$(document).ready(docReady) | ||
|
||
</script> | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
|
||
var jsond = require("./jsond") | ||
var jsond = require("./jsond.js"), | ||
l = console.log | ||
|
||
var log = console.log | ||
|
||
function msgHandler(msg, cb) { | ||
log("incoming msg: "+JSON.stringify(msg)); | ||
function msgHandler(tx, msg, cb) { | ||
l("incoming msg: "+JSON.stringify(msg)); | ||
msg = {r:"You said: "+msg.m} | ||
log("sending response: "+JSON.stringify(msg)); | ||
l("sending response: "+JSON.stringify(msg)); | ||
cb(msg) | ||
} | ||
|
||
jsond.createServer(msgHandler).listen(30304) | ||
jsond.createServer(msgHandler).listen(50505) | ||
|
||
log("listening"); | ||
l("listening"); | ||
|