Module jls.net.TcpServer
Provides TCP server socket class.
Class TcpServer
tcpServer:bind (node, port[, backlog[, callback]]) | Binds this server to the specified address and port number. |
tcpServer:onAccept (client) | Accepts a new TCP client. |
Class TcpServer
The TcpServer class.
A TCP Server allows to listen and accept TCP connections.
- tcpServer:bind (node, port[, backlog[, callback]])
-
Binds this server to the specified address and port number.
Parameters:
- node string the address, the address could be an IP address or a host name.
- port number the port number.
- backlog number the accept queue size, default is 32. (optional)
- callback function an optional callback function to use in place of promise. (optional)
Returns:
-
jls.lang.Promise
a promise that resolves once the server is bound.
Usage:
local s = TcpServer:new() s:bind('127.0.0.1', 80)
- tcpServer:onAccept (client)
-
Accepts a new TCP client.
This method should be overriden, the default implementation closes the client.
Parameters:
- client the TCP client to accept.
Usage:
local s = TcpServer:new() function s:onAccept(client) client:close() end