Hi Everyone,
I am tasked to create a 4gl server socket program that communicates with a 3rd party application. The application uses a 2 byte header prefixed to all messages. The header is used as an indicator of the length of the message excluding the headers. The first
byte contains the quotient of the length of the message and 256 while the second
byte contains the remainder. So if the length of the message is 300, the headers are chr(1) and chr(44). My problem arises when the message received is less than 256 wherein the first byte is chr(0). OE seems to ignore chr(0) thus the 3rd byte becomes part of the header, making the expected length of the message incorrect.
The same is also true when I am the sender of the message. The other application seems to ignore chr(0) and uses the 3rd byte as part of the header. My problem is how to get my application to read and write chr(0) on the 4gl socket. Below is the code that i used to write the message to the socket. I am using OE 10.1C on Windows XP.
Thanks
I am tasked to create a 4gl server socket program that communicates with a 3rd party application. The application uses a 2 byte header prefixed to all messages. The header is used as an indicator of the length of the message excluding the headers. The first
byte contains the quotient of the length of the message and 256 while the second
byte contains the remainder. So if the length of the message is 300, the headers are chr(1) and chr(44). My problem arises when the message received is less than 256 wherein the first byte is chr(0). OE seems to ignore chr(0) thus the 3rd byte becomes part of the header, making the expected length of the message incorrect.
The same is also true when I am the sender of the message. The other application seems to ignore chr(0) and uses the 3rd byte as part of the header. My problem is how to get my application to read and write chr(0) on the 4gl socket. Below is the code that i used to write the message to the socket. I am using OE 10.1C on Windows XP.
Thanks
Code:
/*
This is the part of the code that writes to the socket.
This is working if the message is not less than 256 characters
and not divisible by 256
*/
DEFINE VARIABLE iMessageLength AS INTEGER NO-UNDO.
DEFINE VARIABLE iMsgLen1 AS INTEGER NO-UNDO.
DEFINE VARIABLE iMsgLen2 AS INTEGER NO-UNDO.
DEFINE VARIABLE MessageToWrite AS CHARACTER NO-UNDO.
DEFINE VARIABLE mMsg AS MEMPTR.
MessageToWrite = "This is some message".
SET-SIZE(mMsg) = 0.
iMessageLength = LENGTH(MessageToWrite) + 3.
SET-SIZE(mMsg) = iMessageLength.
iMsgLen1 = TRUNCATE((LENGTH(MessageToWrite)) / 256,0).
iMsgLen2 = (LENGTH(MessageToWrite)) MOD 256.
PUT-STRING(mMsg,1) = CHR(iMsgLen1) + CHR(iMsgLen2) + MessageToWrite.
hMySocket:WRITE(mMsg,1,iMessageLength - 1).