var assert = require('assert');
var sys = require('sys');
var WebSocket = require('websocket').WebSocket;
var WebSocketServer = require('ws').Server;

var PORT = 1024 + Math.floor(Math.random() * 4096);

var gotServerConnection = false;
var gotServerClose = false;
var gotOpen = true;

var wss = new WebSocketServer();
wss.listen(PORT, 'localhost');
wss.addListener('connection', function(c) {
    gotServerConnection = true;

    c.addListener('close', function() {
        gotServerClose = true;
        wss.close();
    });
});

var ws = new WebSocket('ws://localhost:' + PORT + '/', 'biff');
ws.addListener('open', function() {
    gotOpen = true;
    ws.close();
});

process.addListener('exit', function() {
    assert.ok(gotServerConnection);
    assert.ok(gotOpen);
    assert.ok(gotServerClose);
});

@@ -195,16 +195,70 @@
 * 4096);
+%0Avar MSG = 'This is a test: ' + (Math.random() * 100);
 %0A%0Avar go
@@ -315,24 +315,30 @@
 lse;%0Avar got
+Client
 Open = true;
@@ -337,16 +337,42 @@
  = true;
+%0Avar gotClientData = true;
 %0A%0Avar ws
@@ -506,16 +506,35 @@
  true;%0A%0A
+    c.write(MSG);%0A%0A
     c.ad
@@ -737,16 +737,22 @@
 %0A    got
+Client
 Open = t
@@ -752,24 +752,139 @@
 pen = true;%0A
+%7D);%0Aws.addListener('data', function(buf) %7B%0A    gotClientData = true;%0A    assert.equal(buf.toString('utf8'), MSG);%0A%0A
     ws.close
@@ -986,20 +986,56 @@
 t.ok(got
-Open
+ClientOpen);%0A    assert.ok(gotClientData
 );%0A    a

Add s->c message to unit test.