| window.runtime property | window.runtime.flash.net.Socket |
| Inheritance | Socket EventDispatcher Object |
| Runtime Versions: | AIR 1.0, Flash Player 9 |
The Socket class is useful for working with servers that use binary protocols.
When you use this method in content in security sandboxes other than then application security sandbox, consider the AIR security model:
However, in Adobe AIR, content in the application security sandbox (content
installed with the AIR application) are not restricted by these security limitations.
For more information, see the following:
| Property | Defined By | ||
|---|---|---|---|
| bytesAvailable : uint [read-only]
The number of bytes of data available for reading in the input buffer. | Socket | ||
| connected : Boolean [read-only]
Indicates whether this Socket object is currently connected. | Socket | ||
![]() | constructor : Object
A reference to the class object or constructor function for a given object instance. | Object | |
| endian : String
Indicates the byte order for the data; possible values are
constants from the flash.utils.Endian class,
Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN. | Socket | ||
| objectEncoding : uint
Controls the version of AMF used when writing or reading an object. | Socket | ||
![]() | prototype : Object [static]
A reference to the prototype object of a class or function object. | Object | |
| Method | Defined By | ||
|---|---|---|---|
Socket(host:String = null, port:int = 0)
Creates a Socket object. | Socket | ||
![]() | addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener
receives notification of an event. | EventDispatcher | |
Closes the socket. | Socket | ||
Connects the socket to the specified host and port. | Socket | ||
![]() | dispatchEvent(event:Event):Boolean
Dispatches an event into the event flow. | EventDispatcher | |
Flushes any accumulated data in the socket's output buffer. | Socket | ||
![]() | hasEventListener(type:String):Boolean
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | |
![]() | hasOwnProperty(name:String):Boolean
Indicates whether an object has a specified property defined. | Object | |
![]() | isPrototypeOf(theClass:Object):Boolean
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | |
![]() | propertyIsEnumerable(name:String):Boolean
Indicates whether the specified property exists and is enumerable. | Object | |
readBoolean():Boolean
Reads a Boolean value from the socket. | Socket | ||
readByte():int
Reads a signed byte from the socket. | Socket | ||
Reads the number of data bytes specified by the length
parameter from the socket. | Socket | ||
readDouble():Number
Reads an IEEE 754 double-precision floating-point number from the socket. | Socket | ||
readFloat():Number
Reads an IEEE 754 single-precision floating-point number from the socket. | Socket | ||
readInt():int
Reads a signed 32-bit integer from the socket. | Socket | ||
readMultiByte(length:uint, charSet:String):String
Reads a multibyte string from the byte stream, using the specified character set. | Socket | ||
readObject():*
Reads an object from the socket, encoded in AMF serialized format. | Socket | ||
readShort():int
Reads a signed 16-bit integer from the socket. | Socket | ||
readUnsignedByte():uint
Reads an unsigned byte from the socket. | Socket | ||
readUnsignedInt():uint
Reads an unsigned 32-bit integer from the socket. | Socket | ||
readUnsignedShort():uint
Reads an unsigned 16-bit integer from the socket. | Socket | ||
readUTF():String
Reads a UTF-8 string from the socket. | Socket | ||
readUTFBytes(length:uint):String
Reads the number of UTF-8 data bytes specified by the length
parameter from the socket, and returns a string. | Socket | ||
![]() | removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object. | EventDispatcher | |
![]() | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void
Sets the availability of a dynamic property for loop operations. | Object | |
![]() | toString():String
Returns the string representation of the specified object. | Object | |
![]() | valueOf():Object
Returns the primitive value of the specified object. | Object | |
![]() | willTrigger(type:String):Boolean
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher | |
writeBoolean(value:Boolean):void
Writes a Boolean value to the socket. | Socket | ||
Writes a byte to the socket. | Socket | ||
Writes a sequence of bytes from the specified byte array. | Socket | ||
writeDouble(value:Number):void
Writes an IEEE 754 double-precision floating-point number to the socket. | Socket | ||
writeFloat(value:Number):void
Writes an IEEE 754 single-precision floating-point number to the socket. | Socket | ||
Writes a 32-bit signed integer to the socket. | Socket | ||
writeMultiByte(value:String, charSet:String):void
Writes a multibyte string from the byte stream, using the specified character set. | Socket | ||
Write an object to the socket in AMF serialized format. | Socket | ||
writeShort(value:int):void
Writes a 16-bit integer to the socket. | Socket | ||
writeUnsignedInt(value:uint):void
Writes a 32-bit unsigned integer to the socket. | Socket | ||
Writes the following data to the socket: a 16-bit unsigned integer, which
indicates the length of the specified UTF-8 string in bytes, followed by
the string itself. | Socket | ||
writeUTFBytes(value:String):void
Writes a UTF-8 string to the socket. | Socket | ||
| Event | Summary | Defined By | ||
|---|---|---|---|---|
![]() | Dispatched when Flash Player or an AIR application gains operating system focus and becomes active. | EventDispatcher | ||
| Dispatched when the server closes the socket connection. | Socket | |||
| Dispatched when a network connection has been established. | Socket | |||
![]() | Dispatched when Flash Player or an AIR application loses operating system focus and is becoming inactive. | EventDispatcher | ||
| Dispatched when an input/output error occurs that causes a send or load operation to fail. | Socket | |||
| Dispatched if a call to Socket.connect() attempts to connect either to a server outside the caller's security sandbox or to a port lower than 1024. | Socket | |||
| Dispatched when a socket has received data. | Socket | |||
| bytesAvailable | property |
bytesAvailable:uint [read-only] | Runtime Versions: | AIR 1.0, Flash Player 9 |
The number of bytes of data available for reading in the input buffer.
Your code must access bytesAvailable to ensure
that sufficient data is available before trying to read
it with one of the read methods.
| connected | property |
connected:Boolean [read-only] | Runtime Versions: | AIR 1.0, Flash Player 9 |
Indicates whether this Socket object is currently connected.
A call to this property returns a value of true if the socket
is currently connected, or false otherwise.
| endian | property |
endian:String [read-write] | Runtime Versions: | AIR 1.0, Flash Player 9 |
Indicates the byte order for the data; possible values are
constants from the flash.utils.Endian class,
Endian.BIG_ENDIAN or Endian.LITTLE_ENDIAN.
The default value is Endian.BIG_ENDIAN.
See also
| objectEncoding | property |
objectEncoding:uint [read-write] | Runtime Versions: | AIR 1.0, Flash Player 9 |
Controls the version of AMF used when writing or reading an object.
See also
| Socket | () | Constructor |
function Socket(host:String = null, port:int = 0)| Runtime Versions: | AIR 1.0, Flash Player 9 |
Creates a Socket object. If no parameters are specified, an initially disconnected socket is created. If parameters are specified, a connection is attempted to the specified host and port.
Parametershost:String (default = null) — The name of the host to connect to. If this parameter is not specified, an initially disconnected socket
is created.
| |
port:int (default = 0) — The port number to connect to. If this parameter is not specified, an initially disconnected socket
is created.
|
connect: — Dispatched when a network connection has been established. | |
ioError: — Dispatched when an input/output error
occurs that causes the connection to fail. | |
securityError: — This error occurs in SWF content.
Dispatched if a call to Socket.connect() attempts
to connect either to a server outside the caller's security sandbox or to a port lower than 1024. You
can work around either problem by using a cross-domain policy file on the server. (This restriction is
not placed on AIR content running in the application security sandbox.) For more information
about policy files for sockets, see the "Flash Player Security" chapter in
Programming ActionScript 3.0. |
SecurityError — This error occurs in SWF content.
|
| close | () | method |
function close():void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Closes the socket. You cannot read or write any data after the close() method
has been called.
The close event is dispatched only when the server
closes the connection; it is not dispatched when you call the close() method.
You can reuse the Socket object by calling the connect() method on it again.
IOError — The socket could not be closed, or the socket was not open.
|
| connect | () | method |
function connect(host:String, port:int):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Connects the socket to the specified host and port. If the connection fails immediately, either an event is dispatched or an exception is thrown: an error event is dispatched if a host was specified, and an exception is thrown if no host was specified. Otherwise, the status of the connection is reported by an event. If the socket is already connected, the existing connection is closed first.
Parameters
host:String — The name of the host to connect to. If no host is specified,
the host that is contacted is the host where the calling file
resides. If you do not specify a host, use an event listener to
determine whether the connection was successful.
| |
port:int — The port number to connect to.
|
connect: — Dispatched when a network connection has been
established. | |
ioError: — Dispatched if a host is specified and an
input/output error occurs that causes the connection to fail. | |
securityError: — Dispatched if a call to
Socket.connect() attempts to connect to either
a server outside the caller's security sandbox or to a port
lower than 1024. (This restriction is not placed on AIR content
running in the application security sandbox.) You can work
around either problem by using
a cross-domain policy file on the server. For more information,
see the "Flash Player Security" chapter in Programming
ActionScript 3.0. |
IOError — No host was specified and the connection failed.
| |
SecurityError — This error occurs in SWF content.
|
| flush | () | method |
function flush():void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Flushes any accumulated data in the socket's output buffer.
Data written by the write methods is not
immediately transmitted; it is queued until the
flush() method is called.
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readBoolean | () | method |
function readBoolean():Boolean| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a Boolean value from the socket. After reading a single byte, the
method returns true if the byte is nonzero, and
false otherwise.
Boolean — A value of true if the byte read is nonzero,
otherwise false.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readByte | () | method |
function readByte():int| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a signed byte from the socket.
Returnsint — A value from -128 to 127.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readBytes | () | method |
function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads the number of data bytes specified by the length
parameter from the socket. The bytes are read into the specified byte
array, starting at the position indicated by offset.
Parameters
bytes:ByteArray — The ByteArray object to read data into.
| |
offset:uint (default = 0) — The offset at which data reading should begin in the byte
array.
| |
length:uint (default = 0) — The number of bytes to read. The default value of 0 causes
all available data to be read.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is
not open.
|
| readDouble | () | method |
function readDouble():Number| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an IEEE 754 double-precision floating-point number from the socket.
ReturnsNumber — An IEEE 754 double-precision floating-point number.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readFloat | () | method |
function readFloat():Number| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an IEEE 754 single-precision floating-point number from the socket.
ReturnsNumber — An IEEE 754 single-precision floating-point number.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readInt | () | method |
function readInt():int| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a signed 32-bit integer from the socket.
Returnsint — A value from -2147483648 to 2147483647.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readMultiByte | () | method |
function readMultiByte(length:uint, charSet:String):String| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a multibyte string from the byte stream, using the specified character set.
Parameters
length:uint — The number of bytes from the byte stream to read.
| |
charSet:String — The string denoting the character set to use to interpret the bytes.
Possible character set strings include "shift_jis", "CN-GB", and
"iso-8859-1".
For a complete list, see Supported Character Sets.
Note: If the value for the |
String — A UTF-8 encoded string.
|
EOFError — There is insufficient data available to read.
|
| readObject | () | method |
function readObject():*| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an object from the socket, encoded in AMF serialized format.
Returns* — The deserialized object
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| readShort | () | method |
function readShort():int| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a signed 16-bit integer from the socket.
Returnsint — A value from -32768 to 32767.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readUnsignedByte | () | method |
function readUnsignedByte():uint| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an unsigned byte from the socket.
Returnsuint — A value from 0 to 255.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readUnsignedInt | () | method |
function readUnsignedInt():uint| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an unsigned 32-bit integer from the socket.
Returnsuint — A value from 0 to 4294967295.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readUnsignedShort | () | method |
function readUnsignedShort():uint| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads an unsigned 16-bit integer from the socket.
Returnsuint — A value from 0 to 65535.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readUTF | () | method |
function readUTF():String| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads a UTF-8 string from the socket. The string is assumed to be prefixed with an unsigned short integer that indicates the length in bytes.
ReturnsString — A UTF-8 string.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| readUTFBytes | () | method |
function readUTFBytes(length:uint):String| Runtime Versions: | AIR 1.0, Flash Player 9 |
Reads the number of UTF-8 data bytes specified by the length
parameter from the socket, and returns a string.
Parameters
length:uint — The number of bytes to read.
|
String — A UTF-8 string.
|
EOFError — There is insufficient data available to read.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
| writeBoolean | () | method |
function writeBoolean(value:Boolean):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a Boolean value to the socket. This method writes a single byte,
with either a value of 1 (true) or 0 (false).
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:Boolean — The value to write to the socket: 1 (true) or 0 (false).
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeByte | () | method |
function writeByte(value:int):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a byte to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:int — The value to write to the socket. The low 8 bits of the
value are used; the high 24 bits are ignored.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeBytes | () | method |
function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a sequence of bytes from the specified byte array. The write
operation starts at the position specified by offset.
If you omit the length parameter the default
length of 0 causes the method to write the entire buffer starting at
offset.
If you also omit the offset parameter, the entire buffer is written.
If offset or length
is out of range, they are adjusted to match the beginning and end
of the bytes array.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
bytes:ByteArray — The ByteArray object to write data from.
| |
offset:uint (default = 0) — The zero-based offset into the bytes ByteArray
object at which data writing should begin.
| |
length:uint (default = 0) — The number of bytes to write. The default value of 0 causes
the entire buffer to be written, starting at the value specified by
the offset parameter.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeDouble | () | method |
function writeDouble(value:Number):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes an IEEE 754 double-precision floating-point number to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:Number — The value to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeFloat | () | method |
function writeFloat(value:Number):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes an IEEE 754 single-precision floating-point number to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:Number — The value to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeInt | () | method |
function writeInt(value:int):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a 32-bit signed integer to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:int — The value to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeMultiByte | () | method |
function writeMultiByte(value:String, charSet:String):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a multibyte string from the byte stream, using the specified character set.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:String — The string value to be written.
| |
charSet:String — The string denoting the character set to use to interpret the bytes.
Possible character set strings include "shift_jis", "CN-GB",
and "iso-8859-1". For a complete list, see
Supported Character Sets.
|
See also
| writeObject | () | method |
function writeObject(object:*):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Write an object to the socket in AMF serialized format.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
object:* — The object to be serialized.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeShort | () | method |
function writeShort(value:int):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a 16-bit integer to the socket. The bytes written are as follows:
(v >> 8) & 0xff v & 0xff
The low 16 bits of the parameter are used; the high 16 bits are ignored.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:int — The value to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeUnsignedInt | () | method |
function writeUnsignedInt(value:uint):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a 32-bit unsigned integer to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:uint — The value to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeUTF | () | method |
function writeUTF(value:String):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes the following data to the socket: a 16-bit unsigned integer, which indicates the length of the specified UTF-8 string in bytes, followed by the string itself.
Before writing the string, the method calculates the number of bytes needed to represent all characters of the string.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush() method is called.
Parameters
value:String — The string to write to the socket.
|
RangeError — The length is larger than 65535.
| |
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| writeUTFBytes | () | method |
function writeUTFBytes(value:String):void| Runtime Versions: | AIR 1.0, Flash Player 9 |
Writes a UTF-8 string to the socket.
Note: Data written by this method is not
immediately transmitted; it is queued until the flush()
method is called.
Parameters
value:String — The string to write to the socket.
|
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
| close | Event |
flash.events.Eventflash.events.Event.CLOSE| Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when the server closes the socket connection.
The close event is dispatched only when the server
closes the connection; it is not dispatched when you call the Socket.close() method.
Event.CLOSE constant defines the value of the type property of a close event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The object whose connection has been closed. |
| connect | Event |
flash.events.Eventflash.events.Event.CONNECT| Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when a network connection has been established.
TheEvent.CONNECT constant defines the value of the type property of a connect event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The Socket or XMLSocket object that has established a network connection. |
| ioError | Event |
flash.events.IOErrorEventflash.events.IOErrorEvent.IO_ERROR| Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when an input/output error occurs that causes a send or load operation to fail.
Defines the value of thetype property of an ioError event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
errorID | A reference number associated with the specific error. |
target | The network object experiencing the input/output error. |
text | Text to be displayed as an error message. |
| securityError | Event |
flash.events.SecurityErrorEventflash.events.SecurityErrorEvent.SECURITY_ERROR| Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched if a call to Socket.connect()
attempts to connect either to a server outside the caller's security sandbox or to a port lower than 1024.
SecurityErrorEvent.SECURITY_ERROR constant defines the value of the type property of a securityError event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event object with an event listener. |
target | The network object reporting the security error. |
text | Text to be displayed as an error message. |
See also
| socketData | Event |
flash.events.ProgressEventflash.events.ProgressEvent.SOCKET_DATA| Runtime Versions: | AIR 1.0, Flash Player 9 |
Dispatched when a socket has received data.
Events of type socketData do not use the ProgressEvent.bytesTotal
property.
type property of a socketData event object.
This event has the following properties:
| Property | Value |
|---|---|
bubbles | false |
cancelable | false; there is no default behavior to cancel. |
currentTarget | The object that is actively processing the Event. |
bytesLoaded | The number of items or bytes loaded at the time the listener processes the event. |
bytesTotal | 0; this property is not used by socketData event objects. |
target | The Socket object reporting progress. |
Note: To test this example, do the following:
Socket() constructor points to a valid URL and port.
<html>
<head>
<script src="AIRAliases.js" />
<script>
var socket;
var response;
function init() {
socket = new air.Socket("localhost", 80);
socket.addEventListener(air.Event.CLOSE, closeHandler);
socket.addEventListener(air.Event.CONNECT, connectHandler);
socket.addEventListener(air.IOErrorEvent.IO_ERROR, ioErrorHandler);
socket.addEventListener(air.SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
socket.addEventListener(air.ProgressEvent.SOCKET_DATA, socketDataHandler);
}
function writeln(str) {
str += "\n";
try {
socket.writeUTFBytes(str);
}
catch(e) {
air.trace(e);
}
}
function sendRequest() {
air.trace("sendRequest");
response = "";
writeln("GET /");
socket.flush();
}
function readResponse() {
var str = socket.readUTFBytes(socket.bytesAvailable);
response += str;
}
function closeHandler(event) {
air.trace("closeHandler: " + event);
air.trace(response.toString());
}
function connectHandler(event) {
air.trace("connectHandler: " + event);
sendRequest();
}
function ioErrorHandler(event) {
air.trace("ioErrorHandler: " + event);
}
function securityErrorHandler(event) {
air.trace("securityErrorHandler: " + event);
}
function socketDataHandler(event) {
air.trace("socketDataHandler: " + event);
readResponse();
}
</script>
</head>
<body onload='init()'>
</body>
</html>