Created
February 7, 2010 18:17
-
-
Save banksean/297578 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<title>NodeJS Comet Chat Demo</title> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script> | |
<script type='text/javascript'> | |
$(function() { | |
// This only works in modern browsers :) | |
var webSocket = new WebSocket('ws://localhost:8080/chat'); | |
webSocket.onopen = function(event){ | |
$('#status').html('connected'); | |
}; | |
webSocket.onmessage = function(event){ | |
$('#transcript').append(event.data + "<br/>"); | |
}; | |
webSocket.onclose = function(event){ | |
$('#status').html('socket closed'); | |
}; | |
$('#sendButton').click(function() { | |
var text = $('#textEntry').val(); | |
webSocket.send(text); | |
$('#textEntry').val(""); | |
}); | |
}) | |
</script> | |
</head> | |
<body> | |
<h2>Chat</h2> | |
<input type="text" id="textEntry" size="100"></input><button id="sendButton">Send</button> | |
<h2><span id="status">opening socket</span></h2> | |
<div id="transcript"></div> | |
</body> | |
</html> |
This file contains hidden or 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
// Blatantly ripped from amix's slideshow: http://amix.dk/blog/post/19484 | |
var logger = require('../log'); | |
var Module = this.Module = function(){}; | |
var members = []; | |
Module.prototype.onConnect = function(connection) { | |
members.push(connection); | |
}; | |
Module.prototype.onData = function(data, connection){ | |
for (var i in members) { | |
var c = members[i]; | |
c.send(connection == c ? "You: " + data : data); | |
} | |
}; | |
Module.prototype.onDisconnect = function(connection){ | |
for (var i in members) { | |
var c = members[i]; | |
if (members == c) { | |
members.splice(i, 1); | |
break; | |
} | |
} | |
}; |
Mine says opening socket.
ghjghjhjghjghjghj
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Always says Socket Closed