Adobe InDesign CS5.5 Server (7.5) Object Model JS: Socket

InDesign Server CS5.5

Class

Socket

 Creates a TCP/IP connection, or establishes a TCP/IP server.

QuickLinks

Socket, close, listen, open, poll, read, readln, write, writeln

Properties

PropertyTypeAccessDescription
connectedbool readonlyWhen true, the connection is active.
encodingstring r/wSets or retrieves the name of the encoding used to transmit data.
Typical values are "ASCII", "BINARY", or "UTF-8".
eofbool readonlyWhen true, the receive buffer is empty.
errorstring r/wA message describing the most recent error. Setting this value clears any error message.
hoststring readonlyThe name of the remote computer when a connection is established.
If the connection is shut down or does not exist, the property contains the empty string.
timeoutnumber r/wThe timeout in seconds to be applied to read or write operations. (default: 10)

Methods

Constructor

Socket Socket ()
Creates a new Socket object.

Instances

bool close ()
Terminates the open connection.
Returns true if the connection was closed, false on I/O errors.
Deleting the object also closes the connection, but not until JavaScript garbage-collects the object. The connection might stay open longer than you wish if you do not close it explicitly.

bool listen (port: number[, encoding: string=ASCII])
Instructs the object to start listening for an incoming connection.
The call to open() and the call to listen()are mutually exclusive. Call one function or the other, not both.

ParameterTypeDescription
portnumber (range: 1 - 65535) The TCP/IP port number to listen on.
Valid port numbers are 1 to 65535. Typical values are 80 for a Web server, 23 for a Telnet server and so on.
encodingstringThe encoding to be used for the connection (default: ASCII)
Typical values are "ASCII", "BINARY", or "UTF-8". (Optional)

bool open (host: string[, encoding: string=ASCII])
Opens the connection for subsequent read/write operations.
The call to open() and the call to listen() are mutually exclusive. Call one function or the other, not both.

ParameterTypeDescription
hoststringThe server to connect to.
This can be a DNS name, an IPv4 address, or an IPv6 address, followed by a colon and a port number.
encodingstringThe encoding to be used for the connection (default: ASCII)
Typical values are "ASCII", "binary", or "UTF-8". (Optional)

Socket poll ()
Checks a listening object for a new incoming connection.
If a connection request was detected, the method returns a new Socket object that wraps the new connection. Use this connection object to communicate with the remote computer. After use, close the connection and delete the JavaScript object. If no new connection request was detected, the method returns null.

string read ([count: number])
Reads up to the specified number of characters from the connection. CR characters are ignored unless the encoding is set to "BINARY".
Returns a string that contains up to the number of characters that were supposed to be read, or the number of characters read before the connection closed or timed out.

ParameterTypeDescription
countnumberThe number of characters to read.
If not supplied, the connection attempts to read as many characters it can get and returns immediately. (Optional)

string readln ()
Reads one line of text up to the next line feed.
Line feeds are recognized as LF or CRLF pairs. CR characters are ignored. Returns a string containing the characters.

bool write (text: string)
Concatenates all arguments into a single string and writes that string to the connection.

ParameterTypeDescription
textstring Any number of string values. All arguments are concatenated to form the string to be written. CRLF sequences are converted to LFs unless the encoding is set to "BINARY".

bool writeln (text: string)
Concatenates all arguments into a single string, appends a LF character, and writes that string to the connection.

ParameterTypeDescription
textstring Any number of string values. All arguments are concatenated to form the string to be written. CRLF sequences are converted to LFs unless the encoding is set to "BINARY".

Example

See fileSocket.jsx

Return

Socket Socket.Socket ()

Socket Socket.poll ()

Jongware, 28-Apr-2012 v3.0.3iContents :: Index