This document explains the issue with the INIT command response format and how it was fixed to ensure compatibility with Delphi clients.
The Delphi clients (Windows-based) were unable to initialize communication with the Linux server, resulting in the error:
ERRL [Error]Unable to initizlize communication! Terminate connection
The Delphi client uses a specific method to parse the server's response:
// In CloudReportClient.pas (TReportClientThread.FTCPGetCryptoKey):
if not TryStrToInt(FTCPClient.LastCmdResult.Text.Values['LEN'], Len) then
raise EHndError.Create(C_ErrCode_TcpCmd, 'Invalid answer! Missing "LEN" parameter');
CryptoKey_ := FTCPClient.LastCmdResult.Text.Values['KEY'] +
Copy(C_CryptoDictionary[Key], 1, Len) +
Copy(FHostName, 1, 2) + Copy(FHostName, Length(FHostName), 1);
This code has these requirements:
- The response must contain
LEN=value
andKEY=value
on separate lines - These lines must use CRLF line endings (
\r\n
) for proper parsing by Delphi'sTStringList.Values
property - The final line should also end with CRLF for consistency
We've modified the server's response format to match exactly what the Delphi client expects:
LEN=8\r\nKEY=ABCDEFGH\r\n
Key changes:
- Updated
_format_init_response
intcp_server.py
to use format type 14 - Set
INIT_RESPONSE_FORMAT=14
in the.env
file anddocker-compose.yml
- Added validation tests to verify the format works correctly
The correct Delphi-compatible response format (INIT_RESPONSE_FORMAT=14
) is:
LEN=8\r\nKEY=ABCDEFGH\r\n
Where:
LEN
comes beforeKEY
(the order matters for some clients)- Each key-value pair is on its own line
- Lines end with CRLF (
\r\n
) - The response ends with a trailing CRLF
- No additional whitespace around the
=
sign
The crypto key is generated as follows:
- Server sends
LEN
andKEY
in response to INIT - Client constructs the crypto key as:
crypto_key = server_key + crypto_dictionary[key_id-1][:key_length] + hostname[:2] + hostname[-1:]
- This key is then used for encrypting/decrypting all subsequent commands
-
Run the validation test:
./run_format_test.sh
-
This will:
- Set the environment variable
INIT_RESPONSE_FORMAT=14
- Restart the server
- Run
test_format_validation.py
which simulates a Delphi client connection - Verify the response format is correct
- Test that the crypto key can be properly generated and encryption works
- Set the environment variable
If clients still have connection issues:
- Check the server logs for detailed error messages about the INIT response format
- Verify
INIT_RESPONSE_FORMAT=14
is set in both.env
and environment variables - Use
test_format_validation.py
to test if the server is responding correctly - Check for any network issues that might be preventing proper communication
- Verify the crypto dictionary matches between client and server