TGB/Networking/Connecting to a Server
From TDN
TGB Networking >> Connecting to a Server
[edit]
Connecting to a Server
Like the standard StartServerGui dialog handles creating a server, the standard JoinServerGui dialog handles connecting to a server. To connect to a server, all that is required is to simply call:
connectToServer(%serverAddress);
After the connection is attempted, it will either fail, be rejected, or be accepted.
- If the connection is accepted, the client's onConnect() callback is called.
- If the connection fails, the global variable $ServerConnectionErrorMessage will be set to contain the error message, and the client will automatically clean up, call the onDisconnect() callback, and display the error in a message box. Connection failures are handled by the GameConnection::onConnectionError(%this, %msg) method in common/gameScripts/client/serverConnection.cs, which can be overridden in your own code to do any necessary cleanup if a differentiation between a connection error and expected disconnect is needed.
- Connection rejections are handled near identically to connection failures. If the client is rejected (if for example the client were to pass the wrong password to the server or be incompatible in some way), the onDisconnect() callback is called and a message box is displayed with the reason for the rejection.
Categories: Networking | Server | Client | TGB



