diff --git a/src/net.cc b/src/net.cc index 6af7b0b4f4..d8db803baa 100644 --- a/src/net.cc +++ b/src/net.cc @@ -181,8 +181,6 @@ Server::OnConnection (oi_server *s, struct sockaddr *remote_addr, socklen_t remo Server *server = static_cast (s->data); HandleScope scope; - printf("DEBUG: got connection\n"); - Local socket_handle = socket_template->GetFunction()->NewInstance(); Socket *socket = new Socket(socket_handle, 60.0); socket->handle_->Delete(String::NewSymbol("connectTCP")); diff --git a/test/test-echoServer.js b/test/test-echoServer.js new file mode 100644 index 0000000000..8c86abcada --- /dev/null +++ b/test/test-echoServer.js @@ -0,0 +1,49 @@ +include("mjsunit"); +function onLoad() { + server = new Server(1024); + puts("listening at port 12123") + server.listenTCP(12123, function (connection) { + puts("got connection."); + connection.onRead = function (data) { + if (data === null) { + server.close(); + connection.close(); + return; + } + puts ("server read: " + data.toString()); + if (/QUIT/.exec(data)) { + server.close(); + connection.close(); + } else if (/PING/.exec(data)) { + connection.write("PONG"); + } + } + }); + + socket = new Socket; + + var count = 0; + socket.onRead = function (data) { + puts ("client read: " + data.toString()); + assertEquals("PONG", data); + setTimeout(function() { + count += 1; + if (count < 10) { + socket.write("PING"); + } else { + socket.write("QUIT\n"); + socket.close(); + } + }, 100); + }; + socket.onClose = function () { + assertEquals(10, count); + } + + socket.connectTCP(12123, "localhost", function (status) { + if(status != 0) + process.exit(1); + + socket.write("PING"); + }); +}