10-25-2013 08:28 AM
Hi,
I would like to send a big array (a picture in fact) to another computer via a TCP server.
I already use the TCP Support Library to send data to a software running on a different computer and it's working well.
So I did the same thing with a integer array and it doesn't work. I used the sample of Labwindows's help to send this array, and only the first part of the array is received.
I don't understand.
int SendImage(BYTE *lDataToWrite)
{
DWORD dwWaitResult;
int bytesToWrite;
int bytesWritten;
int messageSize;
if (giTCPConnected1 == TRUE)
{
bytesToWrite = messageSize = sizeof(BYTE)*WIDTH*HEIGHT;
while (bytesToWrite > 0)
{
bytesWritten = ClientTCPWrite (giTcpConnection1, &lDataToWrite[messageSize - bytesToWrite], bytesToWrite, 0);
bytesToWrite -= bytesWritten;
}
}
return(ERROR_NO_ERROR);
}
WORD Tab[WIDTH*HEIGHT]; ... ... SendImage(Tab);
int CVICALLBACK ReceiveTcpMsg(unsigned hdl, int event, int error, void *callbackData) {
int iDataSize;
int i,j;
DWORD dwWaitResult;
int bytesToRead;
int bytesRead;
switch (event)
{
case TCP_CONNECT:
giTcpConnection = hdl;
giLineConnected = TRUE;
break;
case TCP_DATAREADY:
// Read tcp/ip data
bytesToRead = messageSize = sizeof(WORD)*WIDTH*HEIGHT;
while (bytesToRead > 0)
{
bytesRead = ClientTCPRead (giTcpConnection, &Tab2[messageSize - bytesToRead], bytesToRead, 0);
bytesToRead -= bytesRead;
}
break;
case TCP_DISCONNECT:
giLineConnected = FALSE;
break;
}
return (0);
}
Is someone has already used these functions with a big data size ?
Or do you know other methods to send an array to an other software ?
Thank you for your help.
Benjamin
Solved! Go to Solution.
10-25-2013 10:42 AM
When I had to perform something similar to your task I have found more confortable to split the dispatch in several smaller pieces (say more or less 3-4k bytes each).
This gave me also the possibility to monitor ethe process and eventually to interrupt it.
10-30-2013 08:18 AM
Thank you for your answer.
I tried to split data in pieces of 3kB and it's seem working. I will finish to test it but it's in good way. Thank you.
Benjamin