GLBasic User Manual

Main sections



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.

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.

NOTE : This command requires that you have purchased either GLBasic Premium or the GLBasic NET add-on.

Example :
FUNCTION ReadHighScores: names$[], scores[], username$, thescore
LOCAL ct, i, str$, proxy$, port

    str$ = "highscores/listgame.php"
    str$ = str$ + "?game=mygame"
    str$ = str$ + "&name="+username$
    str$ = str$ + "&score="+thescore
    str$ = str$ + "&secret=mycode"

    PRINT ".: WebGet scores :.", 0, 0

    INIOPEN "config.ini"
    proxy$ = INIGET$("server", "proxy")
    port = INIGET$("server", "port")
    KILLFILE "scores.ini"
    IF port=0 OR proxy$="NO_DATA"
        NETWEBGET("", "/"+str$, 80, "scores.ini")
        NETWEBGET(proxy$, "" + str$, port, "scores.ini")

    INIOPEN "scores.ini"
    ct = INIGET$("scores", "count")
    DIM names$[ct]
    DIM scores[ct]

    FOR i=1 TO ct
        names$[i-1] = INIGET$("scores", "n"+i)
        scores[i-1] = INIGET$("scores", "s"+i)

See also...