Move tcp library to /tcp.js
This commit is contained in:
parent
0955b0c8de
commit
095470854b
26
doc/api.html
26
doc/api.html
@ -1015,7 +1015,7 @@ Returns a new web server object.
|
||||
</p>
|
||||
<div class="paragraph"><p>The <tt>options</tt> argument is optional. The
|
||||
<tt>options</tt> argument accepts the same values as the
|
||||
options argument for <tt>node.tcp.Server</tt> does.</p></div>
|
||||
options argument for <tt>tcp.Server</tt> does.</p></div>
|
||||
<div class="paragraph"><p>The <tt>request_listener</tt> is a function which is automatically
|
||||
added to the <tt>"request"</tt> event.</p></div>
|
||||
</dd>
|
||||
@ -1464,12 +1464,15 @@ After emitted no other events will be emitted on the response.</p></td>
|
||||
</dd>
|
||||
</dl></div>
|
||||
<h3 id="_tcp">TCP</h3><div style="clear:left"></div>
|
||||
<h4 id="_tt_node_tcp_server_tt"><tt>node.tcp.Server</tt></h4>
|
||||
<div class="paragraph"><p>To use the TCP server and client one must <tt>require("/tcp.js")</tt> or
|
||||
<tt>include("/tcp.js")</tt>.</p></div>
|
||||
<h4 id="_tt_tcp_server_tt"><tt>tcp.Server</tt></h4>
|
||||
<div class="paragraph"><p>Here is an example of a echo server which listens for connections
|
||||
on port 7000</p></div>
|
||||
<div class="listingblock">
|
||||
<div class="content">
|
||||
<pre><tt>function echo (socket) {
|
||||
<pre><tt>include("/tcp.js");
|
||||
var server = createServer(function (socket) {
|
||||
socket.setEncoding("utf8");
|
||||
socket.addListener("connect", function () {
|
||||
socket.send("hello\r\n");
|
||||
@ -1481,8 +1484,7 @@ on port 7000</p></div>
|
||||
socket.send("goodbye\r\n");
|
||||
socket.close();
|
||||
});
|
||||
}
|
||||
var server = node.tcp.createServer(echo);
|
||||
});
|
||||
server.listen(7000, "localhost");</tt></pre>
|
||||
</div></div>
|
||||
<div class="tableblock">
|
||||
@ -1505,7 +1507,7 @@ cellspacing="0" cellpadding="4">
|
||||
<td align="left" valign="top"><p class="table"><tt>"connection"</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table"><tt>connection</tt></p></td>
|
||||
<td align="left" valign="top"><p class="table">Emitted when a new connection is made.
|
||||
<tt>connection</tt> is an instance of <tt>node.tcp.Connection</tt>.</p></td>
|
||||
<tt>connection</tt> is an instance of <tt>tcp.Connection</tt>.</p></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="left" valign="top"><p class="table"><tt>"close"</tt></p></td>
|
||||
@ -1520,7 +1522,7 @@ cellspacing="0" cellpadding="4">
|
||||
</div>
|
||||
<div class="dlist"><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>node.tcp.createServer(connection_listener);</tt>
|
||||
<tt>tcp.createServer(connection_listener);</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
@ -1554,9 +1556,9 @@ event.
|
||||
</p>
|
||||
</dd>
|
||||
</dl></div>
|
||||
<h4 id="_tt_node_tcp_connection_tt"><tt>node.tcp.Connection</tt></h4>
|
||||
<h4 id="_tt_tcp_connection_tt"><tt>tcp.Connection</tt></h4>
|
||||
<div class="paragraph"><p>This object is used as a TCP client and also as a server-side
|
||||
socket for <tt>node.tcp.Server</tt>.</p></div>
|
||||
socket for <tt>tcp.Server</tt>.</p></div>
|
||||
<div class="tableblock">
|
||||
<table rules="all"
|
||||
width="100%"
|
||||
@ -1619,7 +1621,7 @@ cellspacing="0" cellpadding="4">
|
||||
</div>
|
||||
<div class="dlist"><dl>
|
||||
<dt class="hdlist1">
|
||||
<tt>node.tcp.createConnection(port, host="127.0.0.1")</tt>
|
||||
<tt>tcp.createConnection(port, host="127.0.0.1")</tt>
|
||||
</dt>
|
||||
<dd>
|
||||
<p>
|
||||
@ -1721,7 +1723,7 @@ Resumes reading if reading was paused by <tt>readPause()</tt>.
|
||||
<dd>
|
||||
<p>
|
||||
Sets the connection to timeout after <tt>timeout</tt> milliseconds of inactivity on
|
||||
the connection. By default all <tt>node.tcp.Connection</tt> objects have a timeout
|
||||
the connection. By default all <tt>tcp.Connection</tt> objects have a timeout
|
||||
of 60 seconds (60000 ms).
|
||||
</p>
|
||||
<div class="paragraph"><p>If <tt>timeout</tt> is 0, then the idle timeout is disabled.</p></div>
|
||||
@ -1946,7 +1948,7 @@ init (Handle<Object> target)
|
||||
<div id="footer">
|
||||
<div id="footer-text">
|
||||
Version 0.1.12<br />
|
||||
Last updated 2009-09-28 12:23:06 CEST
|
||||
Last updated 2009-09-28 16:05:24 CEST
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
25
doc/api.txt
25
doc/api.txt
@ -625,7 +625,7 @@ Returns a new web server object.
|
||||
+
|
||||
The +options+ argument is optional. The
|
||||
+options+ argument accepts the same values as the
|
||||
options argument for +node.tcp.Server+ does.
|
||||
options argument for +tcp.Server+ does.
|
||||
+
|
||||
The +request_listener+ is a function which is automatically
|
||||
added to the +"request"+ event.
|
||||
@ -942,13 +942,17 @@ After emitted no other events will be emitted on the response.
|
||||
|
||||
=== TCP
|
||||
|
||||
==== +node.tcp.Server+
|
||||
To use the TCP server and client one must +require("/tcp.js")+ or
|
||||
+include("/tcp.js")+.
|
||||
|
||||
==== +tcp.Server+
|
||||
|
||||
Here is an example of a echo server which listens for connections
|
||||
on port 7000
|
||||
|
||||
----------------------------------------
|
||||
function echo (socket) {
|
||||
include("/tcp.js");
|
||||
var server = createServer(function (socket) {
|
||||
socket.setEncoding("utf8");
|
||||
socket.addListener("connect", function () {
|
||||
socket.send("hello\r\n");
|
||||
@ -960,8 +964,7 @@ function echo (socket) {
|
||||
socket.send("goodbye\r\n");
|
||||
socket.close();
|
||||
});
|
||||
}
|
||||
var server = node.tcp.createServer(echo);
|
||||
});
|
||||
server.listen(7000, "localhost");
|
||||
----------------------------------------
|
||||
|
||||
@ -970,14 +973,14 @@ server.listen(7000, "localhost");
|
||||
|=========================================================
|
||||
|Event | Parameters | Notes
|
||||
|+"connection"+ | +connection+ | Emitted when a new connection is made.
|
||||
+connection+ is an instance of +node.tcp.Connection+.
|
||||
+connection+ is an instance of +tcp.Connection+.
|
||||
|+"close"+ | +errorno+ | Emitted when the server closes. +errorno+
|
||||
is an integer which indicates what, if any,
|
||||
error caused the server to close. If no
|
||||
error occurred +errorno+ will be 0.
|
||||
|=========================================================
|
||||
|
||||
+node.tcp.createServer(connection_listener);+ ::
|
||||
+tcp.createServer(connection_listener);+ ::
|
||||
Creates a new TCP server.
|
||||
+
|
||||
The +connection_listener+ argument is automatically set as a listener for
|
||||
@ -1003,10 +1006,10 @@ asynchronous, the server is finally closed when the server emits a +"close"+
|
||||
event.
|
||||
|
||||
|
||||
==== +node.tcp.Connection+
|
||||
==== +tcp.Connection+
|
||||
|
||||
This object is used as a TCP client and also as a server-side
|
||||
socket for +node.tcp.Server+.
|
||||
socket for +tcp.Server+.
|
||||
|
||||
[cols="1,2,10",options="header"]
|
||||
|=========================================================
|
||||
@ -1034,7 +1037,7 @@ socket for +node.tcp.Server+.
|
||||
(TODO: access error codes.)
|
||||
|=========================================================
|
||||
|
||||
+node.tcp.createConnection(port, host="127.0.0.1")+::
|
||||
+tcp.createConnection(port, host="127.0.0.1")+::
|
||||
Creates a new connection object and opens a connection to the specified
|
||||
+port+ and +host+. If the second parameter is omitted, localhost is assumed.
|
||||
+
|
||||
@ -1090,7 +1093,7 @@ Resumes reading if reading was paused by +readPause()+.
|
||||
|
||||
+connection.setTimeout(timeout)+::
|
||||
Sets the connection to timeout after +timeout+ milliseconds of inactivity on
|
||||
the connection. By default all +node.tcp.Connection+ objects have a timeout
|
||||
the connection. By default all +tcp.Connection+ objects have a timeout
|
||||
of 60 seconds (60000 ms).
|
||||
+
|
||||
If +timeout+ is 0, then the idle timeout is disabled.
|
||||
|
28
doc/api.xml
28
doc/api.xml
@ -1062,7 +1062,7 @@ Returns a new web server object.
|
||||
</simpara>
|
||||
<simpara>The <literal>options</literal> argument is optional. The
|
||||
<literal>options</literal> argument accepts the same values as the
|
||||
options argument for <literal>node.tcp.Server</literal> does.</simpara>
|
||||
options argument for <literal>tcp.Server</literal> does.</simpara>
|
||||
<simpara>The <literal>request_listener</literal> is a function which is automatically
|
||||
added to the <literal>"request"</literal> event.</simpara>
|
||||
</listitem>
|
||||
@ -1551,11 +1551,14 @@ After emitted no other events will be emitted on the response.</simpara></entry>
|
||||
</refsect2>
|
||||
<refsect2 id="_tcp">
|
||||
<title>TCP</title>
|
||||
<refsect3 id="_literal_node_tcp_server_literal">
|
||||
<title><literal>node.tcp.Server</literal></title>
|
||||
<simpara>To use the TCP server and client one must <literal>require("/tcp.js")</literal> or
|
||||
<literal>include("/tcp.js")</literal>.</simpara>
|
||||
<refsect3 id="_literal_tcp_server_literal">
|
||||
<title><literal>tcp.Server</literal></title>
|
||||
<simpara>Here is an example of a echo server which listens for connections
|
||||
on port 7000</simpara>
|
||||
<screen>function echo (socket) {
|
||||
<screen>include("/tcp.js");
|
||||
var server = createServer(function (socket) {
|
||||
socket.setEncoding("utf8");
|
||||
socket.addListener("connect", function () {
|
||||
socket.send("hello\r\n");
|
||||
@ -1567,8 +1570,7 @@ on port 7000</simpara>
|
||||
socket.send("goodbye\r\n");
|
||||
socket.close();
|
||||
});
|
||||
}
|
||||
var server = node.tcp.createServer(echo);
|
||||
});
|
||||
server.listen(7000, "localhost");</screen>
|
||||
<informaltable
|
||||
frame="all"
|
||||
@ -1590,7 +1592,7 @@ rowsep="1" colsep="1"
|
||||
<entry align="left" valign="top"><simpara><literal>"connection"</literal></simpara></entry>
|
||||
<entry align="left" valign="top"><simpara><literal>connection</literal></simpara></entry>
|
||||
<entry align="left" valign="top"><simpara>Emitted when a new connection is made.
|
||||
<literal>connection</literal> is an instance of <literal>node.tcp.Connection</literal>.</simpara></entry>
|
||||
<literal>connection</literal> is an instance of <literal>tcp.Connection</literal>.</simpara></entry>
|
||||
</row>
|
||||
<row>
|
||||
<entry align="left" valign="top"><simpara><literal>"close"</literal></simpara></entry>
|
||||
@ -1606,7 +1608,7 @@ rowsep="1" colsep="1"
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<literal>node.tcp.createServer(connection_listener);</literal>
|
||||
<literal>tcp.createServer(connection_listener);</literal>
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
@ -1646,10 +1648,10 @@ event.
|
||||
</varlistentry>
|
||||
</variablelist>
|
||||
</refsect3>
|
||||
<refsect3 id="_literal_node_tcp_connection_literal">
|
||||
<title><literal>node.tcp.Connection</literal></title>
|
||||
<refsect3 id="_literal_tcp_connection_literal">
|
||||
<title><literal>tcp.Connection</literal></title>
|
||||
<simpara>This object is used as a TCP client and also as a server-side
|
||||
socket for <literal>node.tcp.Server</literal>.</simpara>
|
||||
socket for <literal>tcp.Server</literal>.</simpara>
|
||||
<informaltable
|
||||
frame="all"
|
||||
rowsep="1" colsep="1"
|
||||
@ -1713,7 +1715,7 @@ rowsep="1" colsep="1"
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term>
|
||||
<literal>node.tcp.createConnection(port, host="127.0.0.1")</literal>
|
||||
<literal>tcp.createConnection(port, host="127.0.0.1")</literal>
|
||||
</term>
|
||||
<listitem>
|
||||
<simpara>
|
||||
@ -1835,7 +1837,7 @@ Resumes reading if reading was paused by <literal>readPause()</literal>.
|
||||
<listitem>
|
||||
<simpara>
|
||||
Sets the connection to timeout after <literal>timeout</literal> milliseconds of inactivity on
|
||||
the connection. By default all <literal>node.tcp.Connection</literal> objects have a timeout
|
||||
the connection. By default all <literal>tcp.Connection</literal> objects have a timeout
|
||||
of 60 seconds (60000 ms).
|
||||
</simpara>
|
||||
<simpara>If <literal>timeout</literal> is 0, then the idle timeout is disabled.</simpara>
|
||||
|
24
doc/node.1
24
doc/node.1
@ -900,7 +900,7 @@ options
|
||||
argument is optional\. The
|
||||
options
|
||||
argument accepts the same values as the options argument for
|
||||
node\.tcp\.Server
|
||||
tcp\.Server
|
||||
does\.
|
||||
.sp
|
||||
The
|
||||
@ -1364,19 +1364,22 @@ that this response belongs to\.
|
||||
.RE
|
||||
.RE
|
||||
.SS "TCP"
|
||||
To use the TCP server and client one must require("/tcp\.js") or include("/tcp\.js")\.
|
||||
.sp
|
||||
.sp
|
||||
.it 1 an-trap
|
||||
.nr an-no-space-flag 1
|
||||
.nr an-break-flag 1
|
||||
.br
|
||||
node.tcp.Server
|
||||
tcp.Server
|
||||
.RS
|
||||
Here is an example of a echo server which listens for connections on port 7000
|
||||
.sp
|
||||
.sp
|
||||
.RS 4
|
||||
.nf
|
||||
function echo (socket) {
|
||||
include("/tcp\.js");
|
||||
var server = createServer(function (socket) {
|
||||
socket\.setEncoding("utf8");
|
||||
socket\.addListener("connect", function () {
|
||||
socket\.send("hello\er\en");
|
||||
@ -1388,8 +1391,7 @@ function echo (socket) {
|
||||
socket\.send("goodbye\er\en");
|
||||
socket\.close();
|
||||
});
|
||||
}
|
||||
var server = node\.tcp\.createServer(echo);
|
||||
});
|
||||
server\.listen(7000, "localhost");
|
||||
.fi
|
||||
.RE
|
||||
@ -1413,7 +1415,7 @@ T}:T{
|
||||
connection
|
||||
.sp
|
||||
T}:T{
|
||||
Emitted when a new connection is made\. connection is an instance of node\.tcp\.Connection\.
|
||||
Emitted when a new connection is made\. connection is an instance of tcp\.Connection\.
|
||||
.sp
|
||||
T}
|
||||
T{
|
||||
@ -1428,7 +1430,7 @@ Emitted when the server closes\. errorno is an integer which indicates what, if
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
node\.tcp\.createServer(connection_listener);
|
||||
tcp\.createServer(connection_listener);
|
||||
.RS 4
|
||||
Creates a new TCP server\.
|
||||
.sp
|
||||
@ -1471,9 +1473,9 @@ event\.
|
||||
.nr an-no-space-flag 1
|
||||
.nr an-break-flag 1
|
||||
.br
|
||||
node.tcp.Connection
|
||||
tcp.Connection
|
||||
.RS
|
||||
This object is used as a TCP client and also as a server\-side socket for node\.tcp\.Server\.
|
||||
This object is used as a TCP client and also as a server\-side socket for tcp\.Server\.
|
||||
.sp
|
||||
.TS
|
||||
allbox tab(:);
|
||||
@ -1540,7 +1542,7 @@ Emitted once the connection is fully closed\. The argument had_error is a boolea
|
||||
T}
|
||||
.TE
|
||||
.PP
|
||||
node\.tcp\.createConnection(port, host="127\.0\.0\.1")
|
||||
tcp\.createConnection(port, host="127\.0\.0\.1")
|
||||
.RS 4
|
||||
Creates a new connection object and opens a connection to the specified
|
||||
port
|
||||
@ -1635,7 +1637,7 @@ connection\.setTimeout(timeout)
|
||||
Sets the connection to timeout after
|
||||
timeout
|
||||
milliseconds of inactivity on the connection\. By default all
|
||||
node\.tcp\.Connection
|
||||
tcp\.Connection
|
||||
objects have a timeout of 60 seconds (60000 ms)\.
|
||||
.sp
|
||||
If
|
||||
|
12
lib/tcp.js
Normal file
12
lib/tcp.js
Normal file
@ -0,0 +1,12 @@
|
||||
exports.createServer = function (on_connection, options) {
|
||||
var server = new node.tcp.Server();
|
||||
server.addListener("connection", on_connection);
|
||||
//server.setOptions(options);
|
||||
return server;
|
||||
};
|
||||
|
||||
exports.createConnection = function (port, host) {
|
||||
var connection = new node.tcp.Connection();
|
||||
connection.connect(port, host);
|
||||
return connection;
|
||||
};
|
11
src/node.js
11
src/node.js
@ -1,8 +1,5 @@
|
||||
node.tcp.createServer = function (on_connection, options) {
|
||||
var server = new node.tcp.Server();
|
||||
server.addListener("connection", on_connection);
|
||||
//server.setOptions(options);
|
||||
return server;
|
||||
node.tcp.createServer = function () {
|
||||
throw new Error("node.tcp.createServer() has moved. Use require('/tcp.js') to access it.");
|
||||
};
|
||||
|
||||
node.createProcess = function () {
|
||||
@ -28,9 +25,7 @@ node.http.createClient = function () {
|
||||
}
|
||||
|
||||
node.tcp.createConnection = function (port, host) {
|
||||
var connection = new node.tcp.Connection();
|
||||
connection.connect(port, host);
|
||||
return connection;
|
||||
throw new Error("node.tcp.createConnection() has moved. Use require('/tcp.js') to access it.");
|
||||
};
|
||||
|
||||
// Timers
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
http = require("/http.js");
|
||||
|
||||
// Make sure no exceptions are thrown when receiving malformed HTTP
|
||||
@ -19,7 +20,7 @@ var s = http.createServer(function (req, res) {
|
||||
});
|
||||
s.listen(port);
|
||||
|
||||
var c = node.tcp.createConnection(port);
|
||||
var c = tcp.createConnection(port);
|
||||
c.addListener("connect", function () {
|
||||
c.send("GET /hello?foo=%99bar HTTP/1.1\r\n\r\n");
|
||||
c.close();
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
http = require("/http.js");
|
||||
|
||||
var port = 8222;
|
||||
@ -32,7 +33,7 @@ http.createServer(function (req, res) {
|
||||
|
||||
}).listen(port);
|
||||
|
||||
var c = node.tcp.createConnection(port);
|
||||
var c = tcp.createConnection(port);
|
||||
|
||||
c.setEncoding("utf8");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
PORT = 23123;
|
||||
|
||||
binaryString = "";
|
||||
@ -18,7 +19,7 @@ for (var i = 255; i >= 0; i--) {
|
||||
binaryString += S;
|
||||
}
|
||||
|
||||
var echoServer = node.tcp.createServer(function (connection) {
|
||||
var echoServer = tcp.createServer(function (connection) {
|
||||
connection.setEncoding("binary");
|
||||
connection.addListener("receive", function (chunk) {
|
||||
error("recved: " + JSON.stringify(chunk));
|
||||
@ -33,7 +34,7 @@ echoServer.listen(PORT);
|
||||
var recv = "";
|
||||
var j = 0;
|
||||
|
||||
var c = node.tcp.createConnection(PORT);
|
||||
var c = tcp.createConnection(PORT);
|
||||
|
||||
c.setEncoding("binary");
|
||||
c.addListener("receive", function (chunk) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
// settings
|
||||
var port = 20743;
|
||||
var bytes = 1024*40;
|
||||
@ -13,7 +14,7 @@ for (var i = 0; i < bytes; i++) {
|
||||
body += "C";
|
||||
}
|
||||
|
||||
var server = node.tcp.createServer(function (c) {
|
||||
var server = tcp.createServer(function (c) {
|
||||
c.addListener("connect", function () {
|
||||
total_connections++;
|
||||
print("#");
|
||||
@ -24,7 +25,7 @@ var server = node.tcp.createServer(function (c) {
|
||||
server.listen(port);
|
||||
|
||||
function runClient (callback) {
|
||||
var client = node.tcp.createConnection(port);
|
||||
var client = tcp.createConnection(port);
|
||||
client.connections = 0;
|
||||
client.setEncoding("utf8");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
|
||||
|
||||
var tests_run = 0;
|
||||
@ -9,7 +10,7 @@ function pingPongTest (port, host, on_complete) {
|
||||
var count = 0;
|
||||
var client_closed = false;
|
||||
|
||||
var server = node.tcp.createServer(function (socket) {
|
||||
var server = tcp.createServer(function (socket) {
|
||||
socket.setEncoding("utf8");
|
||||
|
||||
socket.addListener("receive", function (data) {
|
||||
@ -43,7 +44,7 @@ function pingPongTest (port, host, on_complete) {
|
||||
});
|
||||
server.listen(port, host);
|
||||
|
||||
var client = node.tcp.createConnection(port, host);
|
||||
var client = tcp.createConnection(port, host);
|
||||
|
||||
client.setEncoding("utf8");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
|
||||
|
||||
var tests_run = 0;
|
||||
@ -8,7 +9,7 @@ function pingPongTest (port, host, on_complete) {
|
||||
var count = 0;
|
||||
var sent_final_ping = false;
|
||||
|
||||
var server = node.tcp.createServer(function (socket) {
|
||||
var server = tcp.createServer(function (socket) {
|
||||
assertTrue(socket.remoteAddress !== null);
|
||||
assertTrue(socket.remoteAddress !== undefined);
|
||||
if (host === "127.0.0.1")
|
||||
@ -42,7 +43,7 @@ function pingPongTest (port, host, on_complete) {
|
||||
});
|
||||
server.listen(port, host);
|
||||
|
||||
var client = node.tcp.createConnection(port, host);
|
||||
var client = tcp.createConnection(port, host);
|
||||
|
||||
client.setEncoding("utf8");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
var N = 50;
|
||||
var port = 8921;
|
||||
|
||||
@ -6,7 +7,7 @@ var c = 0;
|
||||
var client_recv_count = 0;
|
||||
var disconnect_count = 0;
|
||||
|
||||
var server = node.tcp.createServer(function (socket) {
|
||||
var server = tcp.createServer(function (socket) {
|
||||
socket.addListener("connect", function () {
|
||||
socket.send("hello\r\n");
|
||||
});
|
||||
@ -22,7 +23,7 @@ var server = node.tcp.createServer(function (socket) {
|
||||
});
|
||||
server.listen(port);
|
||||
|
||||
var client = node.tcp.createConnection(port);
|
||||
var client = tcp.createConnection(port);
|
||||
|
||||
client.setEncoding("UTF8");
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
PORT = 20444;
|
||||
N = 30*1024; // 500kb
|
||||
|
||||
@ -10,7 +11,7 @@ for (var i = 0; i < N; i++) {
|
||||
|
||||
puts("start server on port " + PORT);
|
||||
|
||||
server = node.tcp.createServer(function (connection) {
|
||||
server = tcp.createServer(function (connection) {
|
||||
connection.addListener("connect", function () {
|
||||
connection.send(body);
|
||||
connection.close();
|
||||
@ -24,7 +25,7 @@ npauses = 0;
|
||||
|
||||
|
||||
var paused = false;
|
||||
client = node.tcp.createConnection(PORT);
|
||||
client = tcp.createConnection(PORT);
|
||||
client.setEncoding("ascii");
|
||||
client.addListener("receive", function (d) {
|
||||
chars_recved += d.length;
|
||||
|
@ -1,8 +1,9 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
PORT = 20443;
|
||||
N = 200;
|
||||
|
||||
server = node.tcp.createServer(function (connection) {
|
||||
server = tcp.createServer(function (connection) {
|
||||
function send (j) {
|
||||
if (j >= N) {
|
||||
connection.close();
|
||||
@ -21,7 +22,7 @@ server.listen(PORT);
|
||||
recv = "";
|
||||
chars_recved = 0;
|
||||
|
||||
client = node.tcp.createConnection(PORT);
|
||||
client = tcp.createConnection(PORT);
|
||||
client.setEncoding("ascii");
|
||||
client.addListener("receive", function (d) {
|
||||
print(d);
|
||||
|
@ -1,11 +1,12 @@
|
||||
include("common.js");
|
||||
tcp = require("/tcp.js");
|
||||
port = 9992;
|
||||
exchanges = 0;
|
||||
starttime = null;
|
||||
timeouttime = null;
|
||||
timeout = 1000;
|
||||
|
||||
var echo_server = node.tcp.createServer(function (socket) {
|
||||
var echo_server = tcp.createServer(function (socket) {
|
||||
socket.setTimeout(timeout);
|
||||
|
||||
socket.addListener("timeout", function (d) {
|
||||
@ -27,7 +28,7 @@ var echo_server = node.tcp.createServer(function (socket) {
|
||||
echo_server.listen(port);
|
||||
puts("server listening at " + port);
|
||||
|
||||
var client = node.tcp.createConnection(port);
|
||||
var client = tcp.createConnection(port);
|
||||
client.setEncoding("UTF8");
|
||||
client.setTimeout(0); // disable the timeout for client
|
||||
client.addListener("connect", function () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user