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
10function func(conn) {
var data;
while (data = conn.read())
conn.write(data);
conn.close();
}
new net.TcpServer(8080, func).start();
inheritance relationship
Constructor
TcpServer
TcpServer constructor, listening on all local addresses
1
2new 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
3new 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
2new 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
1readonly Socket TcpServer.socket;
handler
Handler, the server's current event handling interface object
1Handler TcpServer.handler;
member function
start
start the current server
1TcpServer.start();
stop
Closing the socket aborts the running server
1TcpServer.stop() async;
toString
Returns the string representation of the object, generally returns "[Native Object]", the object can be reimplemented according to its own characteristics
1String 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
1Value TcpServer.toJSON(String key = "");
Call parameters:
- key: String, unused
Return result:
- Value, returns a value containing JSON serializable