Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeHitchens committed Jun 2, 2011
1 parent 7939971 commit 9fd20db
Showing 1 changed file with 38 additions and 4 deletions.
42 changes: 38 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,44 @@ Implements a simple server for sending and receiving JSON messages over HTTP.
An example use case would be a web page using AJAX calls to send msgs to a
server using a custom protocol.

See:
* `test.js`
* `docroot/jsonc.js`
* `docroot/index.html`
### Starting a msg handling server

var jsond = require("./jsond")

function msgHandler(msg, cb) {
console.log("msg="+JSON.stringify(msg));
cb({r:msg.m+" ..."});
}

jsond.createServer(msgHandler).listen(3333)

console.log("listening");


### Sending msgs to the server from the browser

<html>
<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>

<script>
var rcvd = document.getElementById("rcvd")

function changed(v) {
var msg = {m:v}
jsond.send(msg, function(response) {
rcvd.value = "Response: "+o2j(response);
})
}

</script>




0 comments on commit 9fd20db

Please sign in to comment.