Table of Contents

24.1.0 Network Components

You should read the pages at http://gambaswiki.org/wiki/doc/network carefully. They contain a lot of information for the use of the different components and their classes as well as the source codes for some servers and clients.

If you want to test clients that connect to a server on the Internet, it makes sense to test whether the clients can access the Internet. In your projects you can use the following well-commented procedure CheckNetwork() for a test:

[1] Public Sub CheckNetwork()
[2]   Dim sResponse As String
[3]   Dim sIPAddress As String
[4]   Dim sErrText As String
[5]
[6]   'Check connection to router by trying to obtain the IP address of the gateway
[7]   'Test der Verbindung mit dem Router durch Ermittlung der Gateway IP-Adresse
[8]   Shell ("ip route show | grep 'default via' | grep -oE '" & Chr$(40) & "[[:digit:]]{1,3}" & Chr$(92) & "." & Chr$(41) & "{3}[[:digit:]]{1,3}'") To sIPAddress
[9]   If sIPAddress = "" Then
[10]     'Get a brief status of all available network interfaces
[11]     'Hole den Status (Überblick) aller Netzwerk-Schnittstellen
[12]     Shell ("nmcli device status") To sResponse
[13]     sErrText = ("<pre><font face='Noto Sans' size='3'>No connection to lokal router! Please check the router and network connections:")
[14]     sErrText &= "<pre><font face='Monospace' size='2'>" & sResponse
[15]     sErrText &= ("<pre><font face='Noto Sans' size='3'>The application will be terminated.")
[16]     Message.Error(sErrText)
[17]     Quit
[18]   Else
[19]  'Additional check for VMs, which may have provided a gateway address although they have no connection to the router. This is done by trying to connect to the Web-Interface of the router.
[20]  'Zusätzliche Prüfung für VMs, die u.U. eine Gateway-Adresse geliefert haben, obwohl keine Verbindung zum Router besteht! Das wird durch den Versuch eines Verbindungsaufbaus mit dem Web-Interface des Routers geleistet.
[21]     Shell ("wget -q --spider " & "http://" & Left$(sIPAddress, Len(sIPAddress) - 1) & " ; echo $?") To sResponse
[22]     If Left$(sResponse, 1) <> "0" Then
[23]       'Get a brief status of all available network interfaces
[24]       'Hole den Grob-Status aller Netzwerk-Schnittstellen
[25]       Shell ("nmcli device status") To sResponse
[26]       sErrText = ("<pre><font face='Noto Sans' size='3'>No connection to lokal router! Please check the router and network connections:")
[27]       sErrText &= "<pre><font face='Monospace' size='2'>" & sResponse
[28]       sErrText &= ("<pre><font face='Noto Sans' size='3'>The application will be terminated.")
[29]       Message.Error(sErrText)
[30]       Quit
[31]     Endif
[32]   Endif
[33]
[34]   'Check availability of Internet by testing the availability of the Google home page.
[35]   'Verfügbarkeit des Internets testen durch einen Verbindungsaufbau mit der Google-Homepage.
[36]   If Exist("/usr/bin/curl") Then
[37]  'Check whether curl is installed. If yes - use it.
[38]  'Testen, ob curl installiert ist. Wenn ja – nutzen Sie das Programm.
[39]     Shell ("curl ifconfig.me") To sResponse
[40]     'If the Internet was connected, sResponse will contain the external (WAN) IP address.
[41]     'Wenn das Internet verbunden war, enthält sResponse die externe WAN-IP-Adresse.
[42]     'Das ist die IP-Adresse, die vom Provider zugewiesen wurde.
[43]     Print "External WAN IP address: "; sResponse
[44]     If Len(sResponse) <= 7 Then
[45]        Message.Error(("No connection to the Internet!<hr>The application will be terminated."))
[46]       Quit
[47]     Endif
[48]   Else
[49]     'Use this alternative method if curl is not installed
[50]     Shell ("wget -q --spider google.com ; echo $?") To sResponse
[51]     If Left$(sResponse, 1) <> "0" Then
[52]       Message.Error(("No connection to the Internet!<hr>The application will be terminated."))
[53]       Quit
[54]     Endif
[55]   Endif
[56]
[57] End

24.1.0.1 Component gb.net

The gb.net component allows you to implement network clients and network servers in Gambas. It also allows you to manage the serial port (RS232/V24). The component contains the following classes:

24.1.0.2 Component gb.net.curl

The gb.net.curl component implements high-level network protocol management based on the curl library. The component enables the retrieval of http and ftp files - possibly other files - over a network. The component contains the following classes:

24.1.0.3 Component gb.mime

The gb.mime component allows you to parse a string and convert it to a MIME message and vice versa. The component is based on the gmime library. The component contains the following classes:

24.1.0.4 Component gb.net.pop3 and gb.net.smtp

24.1.0.5 Component gb.web

The component gb.web allows you to develop a web application - based on a CGI script. The component contains the following classes:

24.1.0.6 Component gb.markdown

The gb.markdown component allows you to convert the Gambas markdown syntax to HTML. This conversion can be customised by using properties and methods of the Markdown class. The component contains the following classes:

24.1.0.7 Component gb.map

The classes of the gb.map component make it possible to display map tiles from various sources in multiple layers. The component contains the following classes:

24.1.0.8 Component gb.map

With the help of the component gb.dbus you use the D-Bus interface of your computer. The component contains the following classes:

Hint:

You should note that the gb.web.form component - introduced in Gambas 3.9 - is considered deprecated. For new projects, use the adequate component gb.web.gui (3.15).