| %KILL | Index Level | %LSEEK (D3/Unix) |
| Syntax | code = %LISTEN( socket, backlog ) |
| Category | BASIC |
| Type | C Function |
| Description |
marks the specified socket as accepting incoming connections and limits the number of outstanding connections in the system queue.
To compile successfully, the statement 'cfunction socket.builtin' must be included in the source code. 'socket' Is the file descriptor of the local socket returned by a previous call to the FlashBASIC C function '%socket'. 'backlog' Maximum number of outstanding connections. The maximum value for this number is SOMAXCONN defined in the include: 'dm,bp,unix.h socket.h' Upon successful completion, a value of 0 is returned in 'code'. In case of error, a value of -1 is returned and the function 'SYSTEM(0)' is set to the value of 'errno'. |
| Options | |
| See Also | CFUNCTION %BIND %ACCEPT %SOCKET %GETHOSTID %READ (D3/Unix) %CLOSE |
| Example |
cfunction socket.builtin
include dm,bp,unix.h socket.h * Create a socket fd=%socket( AF$INET, SOCKET$STREAM, 0 ) * Bind the socket to a local Ethernet port. * Use default address. if %bind( fd, AF$INET, INADDR$ANY, 1024 )<0 then crt 'bind failed'; stop end * Wait for incoming connection and allow up to * three more to be waiting. %listen( fd, 3 ) * Accept a connection until got them all loop addr=0; port=0 fd=%accept( socket, &addr, &port ) until fd<0 do crt 'Called by address ':addr:', port #':port * Read data from the data link %read( fd, buffer, 1024 ) * Done with this connection, close it %close( fd ) repeat |
| Warnings | Sockets are a BSD extension, which may not be available on all Unix platforms. |
| Compatibility | D3/Unix |
| %KILL | Index Level | %LSEEK (D3/Unix) |