F.1.5. rascal_connect

Starts connectiong to a remote peer.

rrid_t rascal_connect(
	const sock_t *target,
	dispatcher,
	void *context OPTIONAL,
	const char *proto OPTIONAL
);

Parameters. 

target

The address of the peer that the connection is to be established to.

dispatcher

Address of the event dispatcher for this connection.

context

The value that helps the application identify the connection additionally to the request identifier assigned by this function (request identifiers are also persistent and do not change during connection's life time).

proto

Type of the transport protocol that the connection must be established over. Currently, supported values are proto_tcp and proto_udp. With proto_udp, the connection will be established immediately (event dispatcher might be called before the function returns), and the application will be able to exchange datagrams with the remote peer.

Note: the library does not take responsibility for the reliability of the communication process if the connection is made over udp; data may be lost without any notification.

Return value. 

If the connection was successfully scheduled (see rascal_isok), the return value can be used to interact with the connection, such as by reading or writing data with it. The connection can also be closed at any time by calling the rascal_cancel function.

When the function fails, a corresponding error message can be retreived using the rascal_get_errmsg function.

Remarks. 

To establish a connection to a target identified by a symbolic host name, you need to either use the rascal_getaddr function or, alternatively, use the rascal_connect_service function. To connect to a system the numeric address of which is known, the following code would be sufficient:

sock_t peer(80);
rascal_aton("127.0.0.1", &peer.addr, NULL);
rascal_connect(&peer, NULL, dispatcher);