Go to the first, previous, next, last section, table of contents.

### `generate_port`, `try_bind_listen`, `try_connect`, `try_accept`, `register_server`

`generate_port([use_unix])`
  :: Generates a port number.
`try_bind_listen(port)`
  :: Binds and listens on a port.
`try_connect(host,port)`
  :: Connects to a port.
`try_accept(socket,port)`
  :: Accepts a connection request.
`register_server(control_socket,control_port,server_socket,server_port)`
  :: Registers the sockets for which connections are established.

return
  integer or string for `generate_port()`, integer for the others
use_unix
  0 or 1
host
  string
port control_port server_port
  integer or string
socket control_socket server_socket
  integer

- These functions are primitives to establish communications between a client and servers.
- `generate_port()` generates a port name for communication. If the argument is not specified or equal to 0, a port number for Internet domain socket is generated randomly. Otherwise a file name for UNIX domain (host-internal protocol) is generated. Note that it is not assured that the generated port is not in use.
- `try_bind_listen()` creates a socket according to the protocol family indicated by the given port and executes `bind` and `listen`. It returns a socket identifier if it is successful. -1 indicates an error.
- `try_connect()` tries to connect to a port port on a host host. It returns a socket identifier if it is successful. -1 indicates an error.
- `try_accept()` accepts a connection request to a socket socket. It returns a new socket identifier if it is successful. -1 indicates an error. In any case socket is automatically closed. port is specified to distinguish the protocol family of socket.
- `register_server()` registers a pair of a control socket and a server socket. A process identifier indicating the pair is returned. The process identifier is used as an argument of `ox` functions such as `ox_push_cmo()`.
- Servers are invoked by using `shell()`, or manually.

    [340] CPort=generate_port();
    39896
    [341] SPort=generate_port();
    37222
    [342] CSocket=try_bind_listen(CPort);
    3
    [343] SSocket=try_bind_listen(SPort);
    5

    /*
    ox_launch is invoked here :
    %  ox_launch "127.1" 0 39716 37043 ox_asir "shio:0"
    */

    [344] CSocket=try_accept(CSocket,CPort);
    6
    [345] SSocket=try_accept(SSocket,SPort);
    3
    [346] register_server(CSocket,CPort,SSocket,SPort);
    0

`References`
  section `ox_launch`, `ox_launch_nox`, `ox_shutdown`, section `ox_launch_generic`, section `shell`, section `ox_push_cmo`, `ox_push_local`

Go to the first, previous, next, last section, table of contents.