LabWindows/CVI

Content Type
Programming Language
Current manual

ClientTCPWrite

ClientTCPWrite

int ClientTCPWrite (unsigned int conversationHandle, void *dataPointer, size_t dataSize, unsigned int timeOut);

Purpose

Allows your program, acting as a TCP client, to send data to the server.

Note  If the function call is successful the return value is the number of bytes written. It is possible that TCP is not able to write all the data in one call. If necessary, you can check the number of bytes written and call this function repeatedly to write the rest of the data as shown in the following example.

Example Code

char * buffer;
int messageSize;
int bytesToWrite;
int bytesWritten;

/* Initialize buffer and messageSize... */

bytesToWrite = messageSize;

while (bytesToWrite > 0)

{

bytesWritten = ClientTCPWrite (conversationHandle, &buffer[messageSize - bytesToWrite], bytesToWrite, 0);

bytesToWrite -= bytesWritten;

}

Parameters

Input
Name Type Description
conversationHandle unsigned int The conversation handle that uniquely represents the connection between the server and the client.
dataPointer void * Pointer to the data to write. NULL is not allowed.
dataSize size_t Number of bytes to write.

This function returns an error if you pass a value greater than UINT_MAX.
timeOut unsigned int Number of milliseconds that ClientTCPWrite waits for data to be written to the connection. The function returns before the timeout period expires if a portion of the data could be read or written to the port or an error occurs.

If you pass a value of zero, the function uses a default timeout of 5,000 milliseconds.

Return Value

Name Type Description
status int Return value indicating whether the function was successful. Unless otherwise stated, zero represents successful execution and a negative number represents the error code.

You can call the GetTCPSystemErrorString function to obtain a system message that describes the error. The system messages can be more descriptive than the TCP Support Library error codes. To obtain the correct system error message, you must call GetTCPSystemErrorString immediately after calling the TCP Support Library function that failed.

For RegisterTCPServer and RegisterTCPServerEx, the return value is the port number assigned by the system if you passed zero for the port and the function was successful.

For functions that read or write data (ClientTCPRead, ClientTCPWrite, ServerTCPRead, ServerTCPWrite), if the function was successful, the return value is the number of bytes transferred.

You can have a maximum of 255 concurrent conversations and up to 1,024 connections. If you exceed this limit, -kTCP_TooManyConnections will be returned. You may not be able to open the maximum number of connections allowed by LabWindows/CVI because of limitations imposed by the operating system.

Additional Information

Library: TCP Support Library

Include file: tcpsupp.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?