Object built-in object

Object TcpServer

A tcp server object that facilitates the creation of a standard multi-fiber tcp server

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

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 relationship

#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 tcp server listening port
  • listener:Handler, specifies the built-in message handler, handler function, chain processing array, and routing object received by tcp, see detailsmq.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 the machine
  • port: Integer, specify the tcp server listening port
  • listener:Handler, specifies the built-in message handler, handler function, chain processing array, and routing object of the connection received by tcp, see detailsmq.Handler

TcpServer constructor

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

Call parameters:

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

Member properties

socket

Socket, the server currently listening onSocketobject

1
readonly Socket TcpServer.socket;

handler

Handler, the server's current event handling interface object

1
Handler TcpServer.handler;

member function

start

start the current server

1
TcpServer.start();

stop

Closing the socket aborts the running server

1
TcpServer.stop() async;

toString

Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented 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 the set of readable properties defined by the object

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

Call parameters:

  • key: String, unused

Return result:

  • Value, returns a value containing JSON serializable