Seed7 - The extensible programming language
Seed7 FAQ Manual Screenshots Examples Libraries Algorithms Download Links
Libraries AES ARC4 Array ASN.1 Bigfile Bigint Bigrat Bin32 Bin64 Bitdata Bitmapfont Bitset Bitsetof Boolean Browser Bstring Bytedata Cards Category CC config Cgi Cgi dialog Char Charsets Cipher Clib_file Color CLI Commands Complex Console Crc32 Deflate DES Dialog Dir Draw Duration Echo Editline Enable_input Enable_io Enable_output Encoding Environment External_file File File system Float Font Forloop Ftp Getf Gethttp Gethttps Graph Graph_file Gzip Hash Hashsetof Hmac Html_ent Httpserv Idxarray Image Inflate Inflate file Inifile Integer Keybd Line Listener LZW Make Math Msgdigest Null_file Osfiles Picture utility Pixmap_file Pixmapfont PKCS #1 Poll Process Progs Propertyfile Rational Reference Ref_list Scanfile Scanstri Set Shell Smtp Sockbase Socket SQL base Stdio Strifile String Stritext Subrange Tar Text Time TLS/SSL Triple DES Unicode Utf16 Utf8 Vectorfont 3D Vector Wildcard Window Wrinum X.509 Xmldom Xml_ent Zip
Libraries
Listener Source Code
 previous   up   next 

Function Summary
listener
openInetListener (in integer: portNumber)
Create a bound internet listener for a port at localhost.
void
close (inout inetListener: aListener)
Close the listener aListener.
void
listen (in inetListener: aListener, in integer: backlog)
Listen for socket connections and limit the incoming queue.
file
accept (inout inetListener: aListener)
Create a new accepted connection socket for aListener.
void
waitForRequest (inout listener: aListener, inout file: existingConnection, inout file: newConnection)
Wait until a request can be read or an incoming connection is accepted.

Function Detail

openInetListener

const func listener: openInetListener (in integer: portNumber)

Create a bound internet listener for a port at localhost. The listerner is responsible for incoming connections of the specified port. The listener also manages its accepted sockets. Processing requests from port 1080 can be done with:

aListener := openInetListener(1080);
listen(aListener, 10);
while TRUE do
  sock := accept(aListener);
  # Read and process the request from sock.
  close(sock);
end while;

The example above manages requests from different clients sequentially. The function waitForRequest can be used to process interleaved requests from several clients.

Returns:
the bound internet listener.
Raises:
FILE_ERROR - A system function returns an error.
RANGE_ERROR - The port is not in the range 0 to 65535.
MEMORY_ERROR - An out of memory situation occurred.

close

const proc: close (inout inetListener: aListener)

Close the listener aListener. A listener manages accepted sockets (its existing connections). When the listener is closed all references to the listener is removed from the accepted sockets.


listen

const proc: listen (in inetListener: aListener, in integer: backlog)

Listen for socket connections and limit the incoming queue. The backlog argument defines the maximum length to which the queue of pending connections for aListener may grow.

Raises:
FILE_ERROR - A system function returns an error.

accept

const func file: accept (inout inetListener: aListener)

Create a new accepted connection socket for aListener. The function waits until at least one connection request is in the listeners queue of pending connections. Then it extracts the first connection request from the listeners queue. This request is accepted and a connection socket is created for it. A listener manages accepted sockets (its existing connections). When an accepted socket is closed it is signed off from the listener.

Returns:
the accepted connection socket.
Raises:
FILE_ERROR - A system function returns an error.
MEMORY_ERROR - An out of memory situation occurred.

waitForRequest

const proc: waitForRequest (inout listener: aListener, inout file: existingConnection, inout file: newConnection)

Wait until a request can be read or an incoming connection is accepted. The function waitForRequest can be used to process interleaved requests from several clients. A listener manages accepted sockets (its existing connections). This function checks the accepted sockets for available input (it is possible to read without blocking). The port of the listener is also checked for incoming connections. The function returns when input is available for an existing connection or when a new incoming connection was accepted. Processing requests from port 2021 can be done with:

aListener := openInetListener(2021);
listen(aListener, 10);
while TRUE do
  waitForRequest(aListener, existingConnection, newConnection);
  if existingConnection <> STD_NULL then
    # Read and process the request from existingConnection.
  end if;
  if newConnection <> STD_NULL then
    # Send welcome message to newConnection.
  end if;
end while;
Parameters:
existingConnection - A random existing connection, were a read will not block, is assigned. When no existing connection has available input, STD_NULL is assigned.
newConnection - A new accepted connection is assigned. When no incoming connection is present, STD_NULL is assigned.


 previous   up   next