LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

I want To send a complete data file (kind defined by user) to a client By the TCPServerWrite function. ?How I can perform this action?

As example said I want to open locally a text file and put it into a buffer for send to a remote Client. Also a want to know how to send a data struct that has pointers to other data structs, for example :

typedef struct
{
int data1;
int data2;
int data3;
char *data;
}Typ_KindDataA

typedef struct
{
int cmdID;
int data2;
int data3;
char data4[20];
char *data5;
Typ_KindDataA *DataA
}Typ_dataToSendByTCP

I created an filled all the fields from the Typ_dataToSendByTCP also included the fields pointed to DataA and then i tried to send it by the ServerTCPWrite function but when I looked for the s
ame received struct in my client application there's no data corresponding to fields *data5 and *DataA in the struct (i reviewed it with the view variables windows when debbuging the application and I only adviced a message "invalid direction" in the struct I defined for receive the incoming data, and in the server application it only appears the direction of the pointer to the other structs->char* and Typ_DatakindA * ) so!!! how I can send all the data correctly?
0 Kudos
Message 1 of 2
(2,890 Views)
The reason that you are having trouble sending this is because your data type is a pointer. When you send over the pointer in the structure, you are sending a memory address value. This address will point to the data5 on your sending machine but NOT on your receiving machine. The receiving machine may be using this memory address already or may have placed the data in a different memory location. Therefore, the pointer will no longer point to what you want it to point to.

To get around this, you will need to reference your data in a fashion other than using a pointer. You may want to send all of you data in an array instead. I am assuming that you were able to get the "char data4[20];" to work correctly.

Good Luck!

Mike Rakolta
National Instrument
s
0 Kudos
Message 2 of 2
(2,890 Views)