Permalink
Browse files

Merge branch 'master' of github.com:Flotype/now into session-support

  • Loading branch information...
2 parents 04c378c + ee1e703 commit e820a28a497a67caf5306371c8a4ef69d1626459 @steveWang steveWang committed Dec 17, 2011
@@ -0,0 +1,16 @@
+var nowjs = require('../../lib/nodeclient/now.js');
+var now = nowjs.nowInitialize('http://localhost:8080');
+var readline = require('readline');
+var rl = readline.createInterface(process.stdin, process.stdout);
+rl.on('line', function(line){
+ now.distributeMessage(line);
+});
+now.ready(function(){
+ console.log("Chat server running!");
+ rl.question("What's your name? ",function(answer){
+ now.name = answer;
+ });
+});
+now.receiveMessage = function(message,name){
+ console.log("----"+name+": "+message);
+}
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<title>nowjs test</title>
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
+<script src="/nowjs/now.js"></script>
+
+<script>
+$(document).ready(function(){
+ now.receiveMessage = function(message,name){
+ $("#messages").append("<br>" + name + ": " + message);
+ }
+
+ $("#send-button").click(function(){
+ now.distributeMessage($("#text-input").val());
+ $("#text-input").val("");
+ });
+
+
+ now.name = prompt("What's your name?", "");
+
+});
+</script>
+</head>
+
+<body>
+<div id="messages"></div>
+<input type="text" id="text-input">
+<input type="button" value="Send" id="send-button">
+</body>
+</html>
+
@@ -0,0 +1,25 @@
+var http = require('http');
+var sys = require('util');
+var nowjs = require('now');
+var fs = require('fs');
+var server = http.createServer(function (req,res){
+ fs.readFile('./index.html', function(error, content) {
+ if (error) {
+ res.writeHead(500);
+ res.end();
+ }
+ else {
+ res.writeHead(200, { 'Content-Type': 'text/html' });
+ res.end(content, 'utf-8');
+ }
+ });
+});
+everyone = nowjs.initialize(server,{socketio: {"log level": 3}});
+everyone.now.log = function(str){
+ console.log(str);
+}
+everyone.now.distributeMessage = function(str){
+ everyone.now.receiveMessage(str,this.now.name);
+}
+server.listen(8080);
+console.log("Listening on 8080");
Oops, something went wrong.

0 comments on commit e820a28

Please sign in to comment.