
194
6
External Communication Tools
ExtendScript offers tools for communicating with other computers or the Internet using standard
protocols.
X The Socket object supports low-level TCP connections. It is available in the following applications:
Z Adobe Bridge CS5
Z Adobe InDesign CS5
Z Adobe InCopy® CS5
Z Adobe After Effects® CS5
Z Adobe Photoshop CS5
Socket object
TCP connections are the basic transport layer of the Internet. Every time your Web browser connects to a
server and requests a new page, it opens a TCP connection to handle the request as well as the server’s
reply. The JavaScript
Socket object lets you connect to any server on the Internet and to exchange data
with this server.
The
Socket object provides basic functionality to connect to a remote computer over a TCP/IP network or
the Internet. It provides calls like
open() and close() to establish or to terminate a connection, and
read() or write() to transfer data. The listen() method establishes a simple Internet server; the server
uses the method
poll() to check for incoming connections.
Many of these connections are based on simple data exchange of ASCII data, while other protocols, like
the FTP protocol, are more complex and involve binary data. One of the simplest protocols is the HTTP
protocol. The following sample TCP/IP client connects to a WWW server (which listens on port 80); it then
sends a very simple HTTP GET request to obtain the home page of the WWW server, and then it reads the
reply, which is the home page together with a HTTP response header.
reply = "";
conn = new Socket;
// access Adobe’s home page
if (conn.open ("www.adobe.com:80")) {
// send a HTTP GET request
conn.write ("GET /index.html HTTP/1.0\n\n");
// and read the server’s reply
reply = conn.read(999999);
conn.close();
}
After executing this code, the variable reply contains the contents of the Adobe home page together
with an HTTP response header.
Establishing an Internet server is a bit more complicated. A typical server program sits and waits for
incoming connections, which it then processes. Usually, you would not want your application to run in an
endless loop, waiting for any incoming connection request. Therefore, you can ask a
Socket object for an
incoming connection by calling the
poll() method of a Socket object. This call would just check the
Comentários a estes Manuais