code:data:tcpserver
Differences
This shows you the differences between two versions of the page.
code:data:tcpserver [2011/01/27 21:32] – created jmgr | code:data:tcpserver [2011/04/20 20:34] (current) – removed jmgr | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== TcpServer ====== | ||
- | This object allows you to create a TCP server, allowing you to listen to incoming connections. | ||
- | |||
- | ===== Functions ===== | ||
- | |||
- | ==== TcpServer ==== | ||
- | Constructor function. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | var myObject = new TcpServer(events); | ||
- | </ | ||
- | |||
- | === Arguments === | ||
- | - events - (object) the events that can be called | ||
- | * onNewConnection - ([[# | ||
- | |||
- | === Example === | ||
- | <code javascript> | ||
- | var myObject = new TcpServer(); | ||
- | </ | ||
- | <code javascript> | ||
- | var myObject = new TcpServer({ | ||
- | onNewConnection: | ||
- | { | ||
- | Console.print(" | ||
- | } | ||
- | }); | ||
- | </ | ||
- | |||
- | ===== Methods ===== | ||
- | |||
- | ==== listen ==== | ||
- | Start listening for clients. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.connect(address, | ||
- | </ | ||
- | <code javascript> | ||
- | myObject.connect(address); | ||
- | </ | ||
- | <code javascript> | ||
- | myObject.connect(); | ||
- | </ | ||
- | |||
- | === Arguments === | ||
- | - address - (string) the address where to listen (default: all network interfaces) | ||
- | - port - (integer) the port number (default: choose a port automatically) | ||
- | |||
- | === Returns === | ||
- | * (TcpServer) this TcpServer | ||
- | |||
- | === Exceptions === | ||
- | * (ListenError) unable to start listening | ||
- | |||
- | ==== waitForNewConnection ==== | ||
- | Freezes the execution until a new connection arrives or **waitTime** time elapsed. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.waitForNewConnection(waitTime); | ||
- | </ | ||
- | <code javascript> | ||
- | myObject.waitForNewConnection(); | ||
- | </ | ||
- | |||
- | === Arguments === | ||
- | - waitTime - (integer) the time to wait (milliseconds, | ||
- | |||
- | === Returns === | ||
- | * (TcpServer) this TcpServer | ||
- | |||
- | === Exceptions === | ||
- | * (WaitForNewConnectionError) waiting for new connection failed | ||
- | |||
- | ==== nextPendingConnection ==== | ||
- | Returns the next pending connection as a [[code: | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.nextPendingConnection(); | ||
- | </ | ||
- | |||
- | === Returns === | ||
- | * (Tcp) the new client as a [[code: | ||
- | |||
- | === Exceptions === | ||
- | * (NoPendingConnectionError) there is no pending connection | ||
- | |||
- | ==== address ==== | ||
- | Returns the ip address on which this server is listening. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.address(); | ||
- | </ | ||
- | |||
- | === Returns === | ||
- | * (string) the ip address on which this server is listening | ||
- | |||
- | ==== port ==== | ||
- | Returns the port used by this server. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.port(); | ||
- | </ | ||
- | |||
- | === Returns === | ||
- | * (integer) the port used by this server | ||
- | |||
- | ===== Events ===== | ||
- | |||
- | ==== onNewConnection ==== | ||
- | Called when a new client has connected. | ||
- | |||
- | === Syntax === | ||
- | <code javascript> | ||
- | myObject.onNewConnection = function() {}; | ||
- | </ | ||
- | |||
- | === Example === | ||
- | <code javascript> | ||
- | myObject.onNewConnection = function() | ||
- | { | ||
- | var client = myObject.nextPendingConnection(); | ||
- | |||
- | // do something with the client... | ||
- | }; | ||
- | </ | ||
- | |||
code/data/tcpserver.1296163960.txt.gz · Last modified: 2021/02/13 11:23 (external edit)