LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to send an array with ClientTCPWrite

Solved!
Go to solution

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

0 Kudos
Message 1 of 3
(3,691 Views)
Solution
Accepted by topic author Benjamin.J

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.



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,687 Views)

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

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