LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send binary data through TCP communication.

Hi!

I want to send the binary code from the client.
You want to send data to the partner device side using the ClientTCPWrite command.
There is no problem with ASCII transmission, but it is a problem when transmitting in binary form.

The binary code is as follows.

50h 00h 00h ffh ffh 03h 00h 0ch 00h 10h 00h 01h 04h 00h 00h 64h 00h 00h 90h 02h 00h

When inputting the above data into the data buffer for transmission, we have confirmed that the following characters can not be processed because of 00h (Null) and ClientTCPWrite transmission data can not contain nulls.

I will contact you if possible!

0 Kudos
Message 1 of 2
(3,039 Views)

As far as I can remember there is no problem in transmitting NUL data on TCP, provided the correct number of characters to send id supplied to ClientTCPWrite (that is, you cannot use string-related functions like strlen). Here is an abstract from a function we have been using for many years for TCP interprocess communication:

 

int		n, nChar, error;
char	msg[64], data[64];
SYSTEMTIME	startTime, stopTime;

// Build up the message to write to the server (data section)
sprintf (data, "%d;%d,", station, status);
nChar = strlen (data);
memcpy (data + nChar, (char *)&startTime, 16); nChar += 16;
memcpy (data + nChar, (char *)&stopTime, 16);  nChar += 16; data[nChar] = 0;

// Build up message header
sprintf (msg, "%d,%d,", recordType, nChar); n = strlen (msg);
memcpy (msg + n, data, nChar);

// Send message to the server
error = ClientTCPWrite (tcpH, msg, nChar + n + 1, 250);

SYTEMTIME structure contains several NUL bytes as it is a series of WORD numbers (aka shorts) with time/date informations used in Win32 API GetLocalTime () function.

 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(2,998 Views)