mirror of https://github.com/lukechilds/node.git
Ryan
16 years ago
4 changed files with 67 additions and 5 deletions
@ -0,0 +1,42 @@ |
|||
include("mjsunit"); |
|||
var port = 8921; |
|||
|
|||
function onLoad () { |
|||
|
|||
new node.tcp.Server(function (socket) { |
|||
puts("new connection"); |
|||
socket.onConnect = function () { |
|||
socket.send("hello\r\n"); |
|||
}; |
|||
|
|||
socket.onEOF = function () { |
|||
socket.close(); |
|||
}; |
|||
|
|||
socket.onDisconnect = function () { |
|||
socket.server.close(); |
|||
}; |
|||
}).listen(port); |
|||
|
|||
var count = 0; |
|||
var client = new node.tcp.Connection(); |
|||
|
|||
client.encoding = "UTF8"; |
|||
client.onConnect = function () { |
|||
puts("client connected"); |
|||
}; |
|||
|
|||
client.onReceive = function (chunk) { |
|||
puts("got msg"); |
|||
assertEquals("hello\r\n", chunk); |
|||
client.fullClose(); |
|||
}; |
|||
|
|||
client.onDisconnect = function () { |
|||
puts("client disconnected"); |
|||
if (count++ < 5) |
|||
client.connect(port); |
|||
}; |
|||
|
|||
client.connect(port); |
|||
} |
Loading…
Reference in new issue