Object built-in object

Object TcpServer

tcp server object, which can easily create a standard multi-fiber tcp server

Use the TcpServer object to quickly create a tcp server for multi-fiber concurrent processing.

1 2 3 4 5 6 7 8 9 10
function func(conn) { var data; while (data = conn.read()) conn.write(data); conn.close(); } new net.TcpServer(8080, func).start();

Inheritance

#lineWidth: 1.5 #font: Helvetica,sans-Serif #fontSize: 10 #leading: 1.6 #.this: fill=lightgray #.class: fill=white [<class>object|toString();toJSON()] [<this>TcpServer|new TcpServer()|socket;handler|start();stop()] [<class>HttpServer] [<class>HttpsServer] [<class>SslServer] [object] <:- [TcpServer] [TcpServer] <:- [HttpServer] [HttpServer] <:- [HttpsServer] [TcpServer] <:- [SslServer] TcpServer new TcpServer() socket handler start() stop() object toString() toJSON() HttpServer HttpsServer SslServer

Constructor

TcpServer

TcpServer constructor, listening on all local addresses

1 2
new TcpServer(Integer port, Handler listener);

Call parameters:

  • port: Integer, specify the listening port of the tcp server
  • listener: Handler, Specify the built-in message handler, processing function, chain processing array, routing object received by tcp, see details mq.Handler

TcpServer constructor

1 2 3
new TcpServer(String addr, Integer port, Handler listener);

Call parameters:

  • addr: String, specify the listening address of the tcp server, if it is "", it will listen on all addresses of this machine
  • port: Integer, specify the listening port of the tcp server
  • listener: Handler, Specify the built-in message handler, processing function, chain processing array, routing object of the connection received by tcp, see for details mq.Handler

TcpServer constructor

1 2
new TcpServer(String addr, Handler listener);

Call parameters:

  • addr: String, specify unix socket or Windows pipe server listening address
  • listener: Handler, Specify the built-in message handler, processing function, chain processing array, routing object of the connection received by tcp, see for details mq.Handler

Member attributes

socket

Socket, The server is currently listening Socket Object

1
readonly Socket TcpServer.socket;

handler

Handler, Server current event processing interface object

1
Handler TcpServer.handler;

Member function

start

Start the current server

1
TcpServer.start();

stop

Close the socket to terminate the running server

1
TcpServer.stop() async;

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be re-implemented according to its own characteristics

1
String TcpServer.toString();

Return result:

  • String, Returns the string representation of the object

toJSON

Returns the JSON format representation of the object, generally returns a collection of readable attributes defined by the object

1
Value TcpServer.toJSON(String key = "");

Call parameters:

  • key: String, unused

Return result:

  • Value, Returns a value containing JSON serializable