| % | Index Level | %ALARM |
| Syntax | code = %ACCEPT( socket, &address, &port ) |
| Category | BASIC |
| Type | C Function |
| Description |
extracts the first connection on the queue of pending connections, creates a new socket and allocates a new file descriptor.
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'. Upon successful completion, a value of 0 is returned in 'code', and the following FlashBASIC variables are updated: 'address' Originating address of the incoming call. 'port' Originating port number or the incoming call. In the case of an error, a value of -1 is returned and the (FlashBASIC) function 'system(0)' is set to the value of 'errno'. |
| Options | |
| See Also | %LISTEN %GETHOSTID %SOCKET %BIND %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 %listen( fd, 1 ) * Accept a connection addr=0; port=0 fd=%accept( socket, &addr, &port ) crt 'Called by address ':addr:', port #':port * Read data from the data link %read( fd, buffer, 1024 ) |
| Warnings |
Sockets are a BSD extension, which may not be available on all Unix platforms.
Legal integer values must be assigned to the variables 'address' and 'port' before the call. |
| Compatibility | D3/Unix |
| % | Index Level | %ALARM |