LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write message to document over client size

I have create Server and client program. At server I open word document "widget.doc" and It returned valid docHandle.

The Server program then send this "docHandle" to client program by using follow function:

 

Server routine:

 

                 WordRpt_ApplicationNew (VTRUE, &appHandle);
                 GetProjectDir (pathName);
                 strcat (pathName, "\\widget.doc");
                 WordRpt_DocumentOpen (appHandle, pathName, &docHandle);

                  typedef struct{
                        CAObjHandle  DocHandle;
                         char         msg[256];
                   }transmit_s;
              

                   message->DocHandle = docHandle;
                   strcpy(message->msg,"Sample text message");

                   len = sizeof (transmit_s);

                   ClientTCPWrite (hconversation, message, len, 1000) < 0)

 

Client routine:

 

             int CVICALLBACK ServerTCPCB (unsigned handle, int event, int error, void *callbackData)
             {
                   

                     datasize = sizeof (transmit_s);

                      switch (event)
                      {
                              case TCP_CONNECT:
                                 .

                                 .

                                 break;

 

                               case TCP_DATAREADY:            
                                         if ((dataSize = ServerTCPRead (hconversation, message, dataSize, 1000000)) < 0)

                                                    SetCtrlVal (g_hmainPanel, MAINPNL_RECEIVE, "Receive Error\n");
                                         else {

                                                    WordRpt_AppendLine (message->DocHandle, message->msg);
                                          }   

                                         break;

 

 PROBLEM:

 

 The Client routine could not write the message to open document "widget.doc". Am i missing something here?

 Do you have sample program that can do this kind of function.

 

 

 Thanks in advance.

  Hien Dam

 

0 Kudos
Message 1 of 3
(3,374 Views)

Hi Hien Dam,

it seems you are trying to pass a structure over TCP connection, so you may find useful to read this thread that has been recently dicscussed here.



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 3
(3,348 Views)

let me understand: are you trying to send the file named "widget.doc" over a network connection to another computer ?

 

then you are doing it wrong. you open the document with a library which allows you to modify the document. when the library loads the file, it processes the information contained in the document and stores it in an opaque structure to make the processing easier. the structure may contain pointers to other memory blocks (something like, maybe, a linked list of paragraphs or memory blocks containing images data).the document is then no more "self-contained". the structure referencing local memory blocks cannot be read on the remote computer since the pointers are not valid on this other machine.

 

there may be some ways to perform the task this way (using RPC, or other distributed processing capability), but anyway you are using a hammer to kill a flee.

 

try simpler: open the file with fopen(), read the entire file in a buffer using fread(), then send this buffer using ClientTCPWrite(). on the remote computer, create a new file with fopen(), read the content from the network using ServerTCPRead() and write it to the file using fwrite(). don't forget to close the file. and hop ! the file is there on the remote computer ! now you can use your favorite library to process the file. a file on the disk is self-contained, and does not reference informations outside itself.

0 Kudos
Message 3 of 3
(3,336 Views)