ACCEPT Statement
Declares the availability of the server to the local session manager, or establishes a connection to a client that has just requested a connection.
Syntax
ACCEPT accept-string TO session {TIMEOUT minutes} {SETTING error} {RETURNING client-id} [THEN statement(s) | ELSE statement(s)]
Syntax Elements
accept-stringA string with one of the formats described in the section Accept String.
sessionA variable in which to return a 'session handle'; that is, a value that identifies the connection.
minutesAn expression that evaluates to a timeout in minutes. The ELSE clause is executed if a connect request is not received and a session established within this time. If a connect request is not received and the TIMEOUT clause is omitted (or minutes = 0), error is set to 4225 and the ELSE clause is taken.
client-idA variable in which to return a dynamic array containing two attributes that identify the client program; that is:
client-plid^client-system*user-id
where:
client-plid is the PLId of the process running the client program.
client-system is the name of the database running the client program; that is, the name of a Q-type (UNIX) or Remote Database (Windows) entry in the .
user-id is the user-id used to logon the client process. This forms part of the second attribute and is separated from the first part, client-system, by an asterisk (*).
^ represents an attribute mark.
error A variable in which to return an error code number representing any errors detected if the ELSE clause is taken. If the ELSE clause is not taken, the value of error is set to 0. The error codes and corresponding messages are given in File I/O and IPC Error Codes.
statement(s) One or more DataBasic statements, forming a THEN or ELSE clause (or both). At least one statement must be included. The THEN clause is executed if the ACCEPT establishes a session without error; otherwise, the ELSE clause is executed.
Accept String
The accept-string parameter must be a string with one of the following formats:
-
To accept a connection from a Reality client program:
{*PTP*}server
where:
*PTP* specifies that this is a Reality process-to-process connection. Note that, for Reality process-to-process this element is optional.
server is the name by which the client knows this PTP server.
-
To accept a connection from a remote system using raw TCP/IP:
*TCP*host;port=port{;mstimeout=milliseconds}{;option}...
where:
*TCP* specifies that this is a raw TCP/IP connection.
host is the IP address on which to accept a connection. This can be the IP address of a local network interface, blank to listen on all local network interfaces, or for local loopback, either the IP address 127.0.0.1 or "localhost".
port is the port on host from which to accept a connection. Some commonly used port numbers are listed in TCP Parameters.
milliseconds is a timeout in milliseconds which overrides the TIMEOUT specified in the ACCEPT statement (or specifies a timeout if the TIMEOUT clause is omitted).
option is a name/value pair (separated by an equals sign), specifying an optional parameter to be passed to the host.
Examples:
"*TCP*152.114.24.126;port=1045;listen=1"
Listens on port 1045 of the network interface with IP address 152.114.24.126.
"*TCP*;port=52002;listen=1"
Listens on port 52002 of all local network interfaces.
"*TCP*localhost;port=2701;listen=1"
Listens on local loopback port 2701.
Operation
DDA Connections
The ACCEPT statement is used either to declare to the Session Manager that the server is available to any client that might subsequently request connection or it might be used as a reply to accept connection to a client that has just requested connection.
Raw TCP/IP Connections
When using the ACCEPT statement to accept raw TCP/IP connections, you must first create a listening socket by issuing an ACCEPT with the listen option. For example:
ACCEPT "*TCP*152.114.24.126;port=1045;listen=1" TO LISTENSESS ELSE STOP
Incoming connections from this host will then be queued. The listen option specifies the size of the queue (note that the operating system may limit on the size of the queue).
Subsequent ACCEPT calls, specifying the same host and port, but without the listen option, can then be used to fetch connection requests from the queue. For example:
ACCEPT "*TCP*152.114.24.126;port=1045" TO CONNSESS ELSE STOP
When your program has finished with a connection or no longer wishes to accept incoming connections on the specified address, it should issue a disconnect:
DISCONNECT CONNSESS ELSE STOP
Examples
Programming in DataBasic contains example programs that use the ACCEPT statement.