iTP Active Transaction Pages (iTP ATP) Programmer's Guide
ATP Web Page and Script Structure
iTP Active Transaction Pages (iTP ATP) Programmer’s Guide—522292-002
3-18
Using TCP/IP Sockets from JavaScript
1. sendMail creates an atp.socket object to represent a TCP/IP connection. The
constructor implicitly opens a socket.
2. sendMail checks for socket errors. The handleErrors function checks the
error property of the socket object. If an error occurred, handleErrors uses
the global function atp.print to print the error, the close method of the socket
object to close the connection, and the global function atp.quit to stop execution
of the script.
3. sendMail writes the message to the socket, using a series of calls to the write
method of the socket object.
4. After each write to the socket, sendMail checks for socket errors (using
handleErrors), then for SMTP errors (using handleReply). handleReply
checks for errors by setting a timeout with the setSoTimeout method, then
reading the reply message one byte at a time, using a shorter timeout. On an error,
handleReply uses the global function atp.print to print the error, the close
method of the socket object to close the connection, and the global function
atp.quit to stop execution of the script.
This way of reading the reply is specific to the SMTP protocol, which indicates the
length of a message at the beginning of the message. Other sockets protocols might
use different conventions.
5. After sending the whole message, sendMail uses the close method to close the
socket and the global function atp.print to report that the message was sent.