|
|
@ -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. |
|
|
|