I am writing a graphical interface to a monitor process running on one of our Tandem systems, using the WinSock SendData and GetData subroutines. The number of bytes (112) that I think I am sending does not equal the number of bytes (113) received by the monitor process. The extra byte at the end of the record is a NULL. Everything else in the record looks good.

The monitor process will be written in C. At the moment, I am sending to a test server (also written in C) that does some checking of the header info and sends back a simple text message. The header contains the total record byte count. Since it is off by one, an error occurs.

I am hoping someone can tell me where I am picking up the extra byte and if it is an error or not. If it's not an error, then I will just have to increment the record size by 1 and handle the extra byte in the monitor process.

Here is the code involved:

<snippets>
' Globals -------------------------------------------------

Public Type dclStdHeader
ttl_len As Long ' long ttl_len;
msgtype As Long ' long msgtype;
orig_id As Long ' long orig_id;
seq_num As Long ' long seq_num;
tran_type As Long ' long tran_type;
user_def(32) As Byte ' char user_def[32];
End Type

Public Type dclMonitorReq
req_hdr As dclStdHeader
reqid As Integer ' short req;
sysname As String * 8 ' char sys[8];
byCust As String * 8 ' char byCust[8];
byProc As String * 8 ' char byProc[8];
byType As Integer ' short byType;
getProcs As Integer ' short getProcs;
getExceps As Integer ' short getExceps;
End Type

Public MonitorRequest As dclMonitorReq

Public sizeofMonitorReq As Integer

Public ByteArray() As Byte

Public Declare Sub CopyMemory Lib "KERNEL32" _
Alias "RtlMoveMemory" (hpvDest As Any, _
hpvSource As Any, _
ByVal cbCopy As Long)

' Code ----------------------------------------------------

sizeofMonitorReq = LenB(MonitorRequest) ' computes to 112


Public Sub Send_Request(ByVal RecNum As Integer)
' Send the request
Dim bArray() As Byte
Dim vTData As Variant
Dim lLen As Long

' 1st we need to store the record length in the header
' and then convert the record to a byte array so that
' it can be assigned to a variant
With MonitorRequest
.req_hdr.ttl_len = sizeofMonitorReq
lLen = LenB(.req_hdr.ttl_len)
ReDim ByteArray(lLen)
CopyMemory ByteArray(0), .req_hdr.ttl_len, lLen
Swap_Endian lLen ' convert to big endian
CopyMemory .req_hdr.ttl_len, ByteArray(0), lLen
End With
ReDim bArray(sizeofMonitorReq) As Byte
CopyMemory bArray(0), MonitorRequest, sizeofMonitorReq

vTData = bArray
tcpClient.SendData vTData

End Sub
</snippets>

I suspect that a variant ends with a NULL character, but I haven't found anything to confirm this. If so, then in the statement vTData = bArray, bArray is copied to vTData and a NULL is appended increasing the length to 113. If not, then my guess would be that the SendData routine is appending the extra byte.

If all of the above are wrong, then I must be doing something wrong, but I have no idea what that may be.

Can anyone set me straight?