GLBasic User Manual

Main sections


The NET... commands require that you have purchased either GLBasic Premium or the GLBasic NET add-on.

The NET... commands give network functionality to GLBasic programs using the TCP protocol. TCP has the advantage over other protocols that sending and receiving of network messages is ensured.

NETJOINGAME(server$, tcp_port%)

With the NETHOSTGAME command, you can host a new network server.

The value for tcp_port% specifies the TCP network port you wish to use for communication. If you set it to 0, it will use the default tcp port of 27910.
Note : Ports under 1024 are known as "privileged" ports and generally support important network functions (like email and internet traffic). As a result it is a good idea to ensure you choose a port for your project higher than 1024 (maximum is 65535).
Of course, you would use the ports under 1025 if you were specifically writing an application to connect to a service like email or a web server.
NOTE : Linux applications may need root access to open ports 1-1024.
NOTE : If you are having trouble getting client systems to talk to your server, ensure that the port chosen here is allowed through any firewalls that may exist.


This command ends all NET... commands, closes any open connections and releases any memory used.


Returns whether the network engine is currently running. If the server quits, the client engines will be shutdown too.


Creates a player that gets announced to the network server. The network services use "players" for communicating with the server and with other clients.
In the case of an error, 0 is returned.


This command returns the number of players the server is currently aware of.
If the server is stopped, this command returns 0. Note : this command performs a query on the network server, thus it's rather slow.


Returns the ID of a player deleted by NETDESTROYPLAYER() or lost due to a disconnection of a client.
This command only works within the server program. If no player has quit, the return value is 0.
If a player has quit, the server should send a message to all clients informing them about the loss. You should continue to call this function until it returns 0 otherwise you may miss a disconnection if several players are removed simultaneously.

id% = NETGETPLAYERID(index%)

You can use this command for all indices in the range 0 to NETNUMPLAYERS()-1 to get the player IDs.
In case of an error, 0 is returned.

name$ = NETPLAYERNAME$(id%)

Once you have the ID for a player, you can query their display name with this function.

ip$ = NETGETIP$()

This command gets you a list of the IP addresses that are allocated to your computer, so you can tell others what they are.
The IPs are separated by "|" and can be separated with SPLITSTR.
Note : If you are writing an application to talk to systems across the internet rather than over a local network, the IP addresses returned from this command may not be the right ones for other systems to connect to. You may need to check your internet router to see what your internet facing IP address is.


In order to prevent more people from connecting to the server or to prevent existing computers from creating additional players, you can set NETALLOWJOINING FALSE. You must call this function in the server program.
Calling NETHOSTGAME sets this back to TRUE.


This command removes a player from the server. This command must be called from the machine that created the player.

ok% = NETSENDMSG(id_from%, id_to%, text$)

Sends a message from player id_from% to the message mailbox of player id_to%. If id_to% = 0, the message gets sent to all known players (except the sender).
text$ is the text string to send and should not exceed 1023 characters.

msg$ = NETGETMSG$(id%)

With this command you retrieve a message for player id% from their message mailbox that was sent with NETSENDMSG. The player id% must be one you've created - i.e. you can only retrieve your own messages. If no message is available, LEN(msg$)=0.
The message is deleted after it has been retrieved.


Returns the player ID of the sender of the last message received from NETGETMSG$().


Returns an error number followed by a readable error message for the last failed action. You can convert the error into a number by calling ierr% = INTEGER(err$). It not ensured that error numbers are identical on all operating systems.

See also...