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 with 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).run();

Inheritance

%0 object object toString() toJSON() TcpServer TcpServer new TcpServer() socket handler start() stop() object->TcpServer HttpServer HttpServer TcpServer->HttpServer SslServer SslServer TcpServer->SslServer HttpsServer HttpsServer HttpServer->HttpsServer

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 mq.Handler details

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 , specifies the built-in message handler, processing function, chain processing array, routing object of the connection received by tcp, see mq.Handler details

Member attributes

socket

Socket , the Socket object currently listening by the server

1
readonly Socket TcpServer.socket;

handler

Handler , the server's 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