Skip to main content

WRITE Command for TCP Devices

WRITE Command for TCP Devices

The WRITE command sends data to a TCP device from the client or the server after you have established connection with OPEN and USE.

The syntax is as follows:

WRITE x
WRITE ! 
WRITE #

How WRITE Works

WRITE x sends x from the client or server to a buffer after the connection has been established.

WRITE ! and WRITE # do not indicate line and form feed. Instead, they tell InterSystems IRIS to flush any characters that remain in the buffer and send them across the network to the target system.

You can determine the number of writes performed by the current TCP connection using the TCPStats()Opens in a new tab method of the %SYSTEM.INetInfoOpens in a new tab class.

WRITE Modifies $X and $Y

InterSystems IRIS stores the number of characters in the buffer in the $X special variable.

The ASCII characters <return> and <line feed> are not included in this count, as they are not considered part of the record. Flushing the buffer with WRITE ! resets $X to 0, and increases the value of $Y by 1. Flushing the buffer with WRITE # writes the ASCII character <form feed> as a separate record, and resets $Y to 0.

WRITE Command Errors

You can receive a <WRITE> error in any of the following circumstances.

  • If you exceed the maximum string size (1024 characters) without flushing the buffer.

  • If you flush the write buffer when there are no characters in it (TCP/IP ignores records of 0 length).

  • If you send a WRITE command from the server to the client before the server receives a connection request from client. (InterSystems IRIS produces the <WRITE> error on the server.)

WRITE Control Commands

The InterSystems IRIS TCP binding device supports a series of control commands with the WRITE *-n syntax.

Syntax Description
WRITE *-2 On a server-mode session that is currently connected to a client, this command disconnects from the session. To accept a new session, you then execute a new READ command on the device.
WRITE *-3 Sends any buffered output out the TCP connection; that is, executes a TCP SEND operation on the data in the output buffer. If the data is compressed (/GZIP) stream data, *-3 sends the data without marking the compression endpoint. Resets $X to 0. Increments $Y by 1. If there is no buffered output, this command does nothing.
WRITE *-99 Sends compressed (/GZIP) stream data. First marks the data in the output buffer with a compression endpoint, then sends this compressed stream data by executing a TCP SEND operation on the output buffer data.
FeedbackOpens in a new tab