Connection management functions

exception DupConnNameExn
Exception raised if non-unique connection identifiers are used.
exception ElementMissingExn
Exception raised if an attempt is made to use a connection with an unknown connection identifier.
ConnManagementLayer.openConnection: string * string * int → unit
Allows users to connect to external processes as a client. It takes three input parameters. The first of these is the unique string identifier (of type string) to be associated with the new connection. The second and third are the host name and port number that make up the address of an external process. The function first checks to ensure the string identifier given is unique, by searching the existing connections. A DupConnNameExn exception is raised if this is not the case. The function then attempts to create a connection to the external process. If successful, the appropriate information is stored and added to the list of connections. The return type of this function is type unit.
ConnManagementLayer.acceptConnection: string * int → unit
Provides server behavior, and allows external processes to connect to CPN Tools. The first argument must be a unique string identifier to be associated with the connection. The second argument is a port number. The function checks that the string identifier is unique, and then listens on the given port for incoming connection requests. This causes CPN Tools to block until an incoming connection request is received. When this happens, a connection is established with the external process requesting the connection
ConnManagementLayer.send: string * 'a * ('a → Word8Vector.vector) → unit
Allows users to send any type of data to external processes. The function is polymorphic, in the sense that the data passed to it for sending can be of any type, including user defined types. Three parameters are passed to this function as input. The first is a string identifier for the connection, the second is the data to send, and the third is a function to encode the data to send. The purpose of the encoding function is to encode the data to send into a sequence of bytes. This allows the data to be of any type, provided an encoding function exists for that type. The send function retrieves the connection corresponding to the given string identifier. The return type of this function is type unit.
ConnManagementLayer.receive: string * (Word8Vector.vector → 'a) → 'a
Allows users to receive any type of data from an external process. The receive function is polymorphic in the same way as the ConnManagementLayer.send function. The parameters to this function are a string identifier for a connection and a decoding function, to decode the received byte vector into the appropriate data type. The resulting decoded data is returned.
ConnManagementLayer.canreceive: string → bool
Checks if input is available on the connection specified by the string identifier.
ConnManagementLayer.closeConnection: string → unit
Allows users to close a connection. The string identifier of the connection to be closed is passed to this function as the argument. A search of the connections is conducted to ensure that a connection exists with that string identifier. If the connection does not exist, an ElementMissingExn exception is raised.

Encode and decode functions

stringEncode s
Converts string s to a Word8Vector.vector
stringDecode v
Converts Word8Vector.vector v to a string
integerEncode i
Converts integer i to a Word8Vector.vector
integerDecode v
Converts Word8Vector.vector v to an integer

Related pages