Socket data protocol with binary data size
Posted: Fri Dec 14, 2012 8:09 pm
I am writing an application that has to run on a PC, but talks via socket communications with a Linux instance on an IBM mainframe. The problem comes in with the data format.
Each transmission has a four byte (full word, 32bit integer, etc.) size that is transmitted before the data packet. And of course, a PC is byte order reversed from the mainframe.
Rather than try to deal with that on the host side, I usually have the remote applications translate a 32bit integer with the file size in it into the host order I need and just transmit it as a binary array. I reverse that process on the way back, taking a BigEndian full word integer and translating it to a LittleEndian 32 bit integer.
I thought I could do this with binaryDecode, but for the life of me, I cannot seem to get it work. Help? Please?
Basic sample code below.
-Paul
Each transmission has a four byte (full word, 32bit integer, etc.) size that is transmitted before the data packet. And of course, a PC is byte order reversed from the mainframe.
Rather than try to deal with that on the host side, I usually have the remote applications translate a 32bit integer with the file size in it into the host order I need and just transmit it as a binary array. I reverse that process on the way back, taking a BigEndian full word integer and translating it to a LittleEndian 32 bit integer.
I thought I could do this with binaryDecode, but for the life of me, I cannot seem to get it work. Help? Please?

Basic sample code below.
-Paul
Code: Select all
local XMLText
local XMLTextL
local MFFormatTextL
on mouseUp
open socket to "zlin040:3706" with message "clientConnected"
end mouseUp
on clientConnected pSocket
put "<IM08XMLI><PROCCD>10</PROCCD><PIDCD></PIDCD><DESKNO>5PR</DESKNO>" & \
"<FILECD></FILECD><DOCTYPE>11</DOCTYPE><DOCDATE>20121214</DOCDATE>" & \
"<PAGECNT>0001</PAGENCT><PRIPOL>7100001301</PRIPOL><STAGEID></STAGEID>" & \
"</IM08XMLI>" & return \
into XMLText
put length(XMLText) into XMLTextL
add 4 to XMLTextL
put binaryDecode("M1",XMLTextL, MFFormatTextL) into theResult
-- write to the socket
write MFFormatTextL to socket pSocket
write XMLText to socket pSocket
read from socket pSocket for 4 bytes
put it into MFFormatTextL
put zero into XMLTextL
put binaryDecode("S1", MFFormatTextL, XMLTextL) into theResult
answer "Return Data size is [" & XMLTextL & "]"
subtract 4 from XMLTextL
if XMLTextL > 0 then
read from socket pSocket for XMLTextL bytes
put "Received: [" & it & "]" into field txtResponse
else
put "A Read error occurred, XMLTextL = " & XMLTextL into field txtResponse
end if
close socket pSocket
end clientConnected