Project23 - SparePartsManagement
Project23 - SparePartsManagement
Project23 - SparePartsManagement
Math Server
It is time to implement a more comprehensive network application by using the socket
programming APIs you have learned in the pervious lab. A sample math client-server interaction
demonstrating online math server that can perform basic math operations.
The basic math interface is shown as follows:
The implementation of this interface is not related to any network operations. The following code
shows a very simple implementation of this interface:
The implementation of the MathServer (Main) is quite straightforward, which looks pretty similar
to the echo server mentioned previously. The difference is that the MathServer have to reconsider
the specific protocol defined by the math server and client communication. The program uses a
very simple protocol operator:first_value:second_value. It is the math server’s responsibility to
understand this protocol and delegate to the proper methods such as add, sub, mul or div.
A test client program that can access the math server is shown below:
URL Encoding
It is very important that the Web can be accessed via heterogeneous platforms such as Windows,
Linux, or Mac. The characters in the URL must come from a fixed subset of ASCII in order to
maintain the interoperability between various platforms. Specifically, the capital letters A-Z, the
lowercase letter a-z, the digits 0-9 and the punctuation characters. Encoding is very simple, any
characters that are not ASCII numerals, letters, or the punctuation marks allowed are converted
into bytes and each byte is written as a percentage sign followed by two hexadecimal digits. For
example, the following program helps encode a query string if non-ASCII characters are present.
Lab Activities
1. Write a URL-based program that pulls content from https://www.comsats.edu.pk/
2. Rewrite the math server application, instead of using TCP socket, use the UDP datagram
socket.
3. Try to run a server program on one machine and the client program on another machine
and see if it works. It works actually, all you have to do is to find out how.
4. Currently the server is closed as soon as it responds to the client. Can you make it like the
real word servers? The server should never be down, and the clients can be many.