Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

How do I design the protocol to transfer data between server and client

Title: How do I design the protocol to transfer data between server and client? A protocol is simply a set of rules. It is important to design the protocol before coding the Delphi program or the PHP script. Think about what we are trying to do. We want the Delphi program to send a day and a month to the PHP script which will then query the MySQL table to obtain the names of all the people who were born on that day and month. We then want the PHP script to send a list of names back to the Delphi program. The list may contain zero or more names. So we need to send the PHP script a day number and a month number. Let's decide upon the name of the PHP script. We'll call it 'birthdays.php'. Now if you type the following into your web browser you will get a response indicating that you haven't submitted any parameters www.pealbase.34sp.com/birthdays.php The way you submit parameters is to append a question mark and then a name-value pair. Subsequent parameters are prefixed by an ampersand. So our request for a list of names that were born on 24th July would be www.pealbase.34sp.com/birthdays.php?day=24&month=7 It is a good idea to write this down as both the Delphi program and the PHP script have to use this protocol. Now we could return the data in a number of ways. But a good way is to return the data as a web page because this can be displayed and checked by using a web browser and without going near Delphi. So the returned web page will consist of zero or more names within paragraph tags. For example: Alan Shearer Laurent Robert Of course the other usual HTML code will surround these paragraph tags in the returned web page. And that's all there is to this birthday protocol. It might be a good idea to enhance the protocol to specify what happens if an invalid day or month is supplied but I will leave that to you.