Adobe 12040118 - After Effects Standard Using Manual page 222

Using help
Hide thumbs Also See for 12040118 - After Effects Standard:
Table of Contents

Advertisement

Adobe After Effects Help
Using Help
Appendix A: The 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, or read() or write()
to transfer data. The object also contains a listen() method to establish 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;
/ / a cces s Ado b e' s ho m e p age
if (conn.open ("www.adobe.com:80")) {
// send a HT TP GET re quest
conn.w r i te ("GET /index.ht ml HT TP/1.0\n\n");
// and read the ser ver's reply
reply = conn.read();
conn.close();
}
After executing above code, the variable homepage contains the contents of the Adobe home page together
with a 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 incoming connec-
tions and then return immediately. If there is a connection request, the call to poll() would return another
Socket object containing the brand new connection. Use this connection object to talk to the calling client;
when finished, close the connection and discard the connection object.
Before a Socket object is able to check for an incoming connection, it must be told to listen on a specific port,
like port 80 for HTTP requests. Do this by calling the listen() method instead of the open() method.
The following example is a very simple Web server. It listens on port 80, waiting until it detects an incoming
request. The HTTP header is discarded, and a dummy HTML page is transmitted to the caller.
conn = new Socket;
// listen on por t 80
if conn.listen (80)) {
// wait fore ver for a connection
var incoming;
do i n co m in g = conn . p o ll();
Using Help
The Socket Object
Back
222
Back
222

Advertisement

Table of Contents
loading

This manual is also suitable for:

After effects

Table of Contents