Good afternoon, dear habrochityvatel!
This topic is an echo of the past.
It was back in 2006. It was necessary to write a term paper on “networks”, and the task had to be invented by myself, the main thing is that in the course there was a program using a client-server architecture. I do not know who bit me and for what place, but I suggested a program for obtaining images from a networked flatbed scanner. In other words, there are two computers nearby and they have one scanner for two. I suppose that now it is already full of such implementations of both software and hardware, but this work has been done for a long time and I wanted to share this development with you, dear habro users.
')
The idea was as follows:
The server that was supposed to work with the TWAIN driver, get a list of installed drivers and possible settings, scan the image and send it over the network to the client.
A client who could get a list of scanners from the server, set the settings for the scanner and eventually get a picture.
Unfortunately, there was very little development time and it wasn’t possible to figure out the TWAIN driver and quickly found a replacement in the form of a shareware console program that simply scanned and saved the image in the designated folder, and since the program was paid, it inserted its text into the scanned picture, something like Demo Version. For coursework, this was perfectly acceptable; moreover, it was done on the last night before handing over this work and it was all the same.
I started developing all this on Qt3 under windows. A server and a client were developed, in addition, a TWAIN scanner emulator was used, so that each time the real scanner would not wait for it to scan, while the virtual one would immediately give the picture. The communication protocol was developed in the simplest way: 1 byte packet size, then a byte of the packet type, and then additional information (optional).
Here I found my report
(link for download on ifolder) for this course, but here is an extract from it:
Description of the client and server interaction protocol.
3.1.1 The protocol is based on the following structure: The first bit of any message is the packet size, with the exception of the packet containing the picture, when sending a picture, the size is 2 bytes. The minimum packet size is 2 bytes. After the first byte, the size is followed by the control character: for the client from 0 to 3, for the server from 0 to 7. When sending a picture after the control symbol, there is a number long with the size of the picture itself, and then the picture itself.
3.1.2 Control characters for the client:
3.1.2.1 0 - The last operation on the server was successful;
2.1.2.2 1 - An error occurred on the server, followed by the size of the string of one byte and then the string itself with the description of the error;
3.1.2.3 2 - A list of TWAIN drivers is received, followed by a byte of the number of drivers, and then the size of the string with the name of the first driver, after which the string itself, then the size and string again, as many times as the drivers received from the server.
3.1.2.4 3 - The picture was received, then the long with the size of the picture and the picture itself.
3.1.3 Control characters for the server.
3.1.3.1 0 - Reset settings.
3.1.3.2 1 - greeting, then goes 1 byte with the version number of the client, if the version does not match the version of the server, the connection is closed.
3.1.3.3 2 - A request for a list of TWAIN drivers, upon receiving such a request, the server sends a list of TWAIN drivers to the client (this function is not available in this version).
3.1.3.4 3 - Select the default driver.
3.1.3.5 4 - A driver is received for operation, after which there is 1 byte of the size of the string, then a string with the name of the driver.
3.1.3.6 5 - The type of image to scan, followed by 1 byte with the size of the string, then a line with the type of image.
3.1.3.7 6 - Start scanning, the server starts scanning, and then sends the image to the client.
3.1.3.8 7 - Set the resolution of the picture, followed by 2 bytes (int) with the extension of the picture.
Server:
The server does not have a graphical user interface. The server waits for the client to connect in the background, after which it accepts the settings and sends answers about how these settings are made. Then it waits for a scan request from the client. The client can also immediately send a request for a scan, in which case all settings will be the default. When a scan command is received, the server launches the command line utility to scan the image, saving it to file page001.jpg or in another, selected format, and then sends it over the network to the client’s computer.
Customer:

The user is prompted to enter client settings. Initially, the default settings are entered. In the column Server Name or IP Address, enter the computer name or its IP address where the scan server is running.
In the column select the driver, you can choose a driver or leave the default driver. (In this version of the program, only the default driver is available).
Then you can choose the settings of the received image from the scanner: image resolution, format and path for saving on the client’s computer. Also available is the function to overwrite the file if it exists.
When you click the join button, the client tries to connect to the server, if the connection occurs, the scan and disconnect functions become available.
Pressing the exit button ends the scanning client program.
The text field is intended to display information about the progress of the program.
Clear button to clear the text field.
When you click the scan button, the selected settings and the scan command are sent to the server. At the end of the scan, the server sends the answer and the picture is displayed on the right side of the program, here the interface picture with the result already received from the server.
Well, actually the archive with all of this -
download .
The source code did not describe in the article itself, everything is in the archive.
Thank you all for your attention.