Overview of Networking
- Object Pascal (in Delphi and Lazarus);
- Smart Pascal;
- Oxygene for Java;
- RemObjects C# for Java.
Downloading text files from a website
In this section "text file" comprises files including HTML that can be read with a reader such as InputStreamReader (as opposed to binary files). The Oxygene demonstration Reading Web Documents and its RemObjects C# equivalent output the downloaded HTML file content and some of its header data. Our simple demonstration with PasSFML in Lazarus outputs the content of the same file.
The Smart Pascal demonstration HTTP loads inet.txt from a web server and also shows the response to a request for a file that does not exist on the server.
Our client-server programs in Oxygene for Java and RemObjects C# demonstrate the use of sockets. See the introduction, the Oxygene for Java server and client and the RemObjects C# equivalent server and client.
The Smart Pascal client-server echo programs make use of a file to store the latest data so that they will work with several commonly used browsers.
The above are simple echo servers. For a service that is helpful finding words in the dictionary that match letter patterns input into the client program see Client and Server Version of Crossword.
Max Foster's NetworkChat shows you how to use SDL in Lazarus for networking. NetworkChat works with a networked Raspberry Pi and PC. You could use Max's SuperMaximo SDL AppEngine to make it easier for you to write your networking program in Lazarus on the Pi.
We demonstrate a simple server and client using PasSFML in Lazarus.
See our tutorial page for our advice on how to start networking in C.
Accessing Databases on Websites
The Smart Pascal program Loading data from a MySQL database on the website uses these PHP scripts to retrieve the data from a MySQL database. A Smart Pascal Node.js server retrieves data from a Firebird database on a Raspberry Pi and sends it to be displayed in a memo on the Smart Pascal client that sent the SQL statement.
Embedding a Web Browser in an Application
You can easily adapt the following demonstration (designed to display your own HTML help files) to navigate to websites instead of accessing local files: Showing Help with the TWebBrowser Component in Delphi 7
An easier alternative in Windows is to call ShellExecute to open a browser with the required page. See Omar Hamid-Chohan's program Cars for sample code.