C4 Engine
C4 Engine API Documentation

NetworkMgr::Connect

Defined in:  C4Network.h
Attempts to establish a connection with another machine.
NOTE. This is a low-level function that is normally called exclusively by the Message Manager. Calling this function directly is not recommended if the Message Manager is being used.
Prototype

void Connect(const NetworkAddress& address);

Parameters
address The address of the machine with which to establish a connection.
Description
The Connect function initiates an attempt to connect to the remote server whose address is given by the address parameter. This function returns immediately and the Network Manager begins listening for a response.

If the connection is accepted by the server, then the Network Manager on both the client machine and the server machine calls the currently installed network event procedure, if any. The low-level network event procedure can be set using the NetworkMgr::SetNetworkEventCallback function, but this procedure should not be changed if the Message Manager is being used. Instead, the Message Manager will call the Application::HandleConnectionEvent function when a connection is accepted.

If the connection is denied by the server, or if the connection attempt times out, then the network event procedure is called with the kNetworkEventFail event on the client machine. The value of the param parameter passed to the network event procedure is one of the following constants indicating why the connection could not be made.
kNetworkFailTimeout The remote machine did not respond and the connection attempt timed out.
kNetworkFailWrongProtocol The remote machine is not using the same communications protocol that the local machine is using.
kNetworkFailNotServer The remote machine is using the correct protocol, but it is not a server.
kNetworkFailServerFull The remote machine did not accept the connection because the maximum number of clients have already connected.
When the Message Manager receives this event, it calls the Application::HandleConnectionEvent function with the kConnectionAttemptFailed event and passes the same failure code the application.

The number of attempts to make a connection and the time interval between attempts are same as those used for reliable packet transmission. These values can be changed using the NetworkMgr::SetReliableResendCount and NetworkMgr::SetReliableResendTime functions.
See Also

NetworkAddress

MessageMgr

NetworkMgr::Disconnect

NetworkMgr::SetNetworkEventCallback

MessageMgr::Connect

Application::HandleConnectionEvent