chickadee » bokbok » open-connection!

open-connection! address username key request-handler close-handlerprocedure

Opens a connection, returning a connection object.

address can be in any of the following forms:

  • "HOSTNAME:PORT" or (tcp HOSTNAME PORT) for a TCP connection
  • "PATH/TO/SOCKET" or (unix "PATH/TO/SOCKET") for a UNIX domain connection

username and key will be used to authenticate and encrypt the connection; the server can't accept the connection unless the key matches what it expects for that username. So if you or the server have not got the right key, the connection will fail.

For an unencrypted and unauthenticated insecure connection, set username and key to #f.

request-handler is a callback that will be invoked (in a thread) for any requests that come from the server. It will be applied to two arguments: the connection object itself and the request received from the server. Its return value will be taken as the response to the request and sent back to the server. Any errors raised in the request-handler will be sent back to the server.

close-handler is a callback that will be invoked (in a thread) if the connection is closed by the server. It will be applied to a single argument, the connection object.

open-connection returns the connection object.