Package | flash.net |
Class | public class Socket |
Inheritance | Socket EventDispatcher Object |
Implements | IDataInput, IDataOutput |
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
The Socket class is useful for working with servers that use binary protocols.
To use the methods of the Socket class, first use the constructor, new Socket
,
to create a Socket object.
SWF files in the local-with-filesystem sandbox may not use sockets.
Socket policy files on the target host specify the hosts from which SWF files can make socket connections, and the ports to which those connections can be made. The security requirements with regard to socket policy files have become more stringent in the last several releases of Flash Player. In all versions of Flash Player, Adobe recommends the use of a socket policy file; in some circumstances, a socket policy file is required. Therefore, if you are using XMLSocket objects, make sure that the target host provides a socket policy file if necessary.
The following list summarizes the requirements for socket policy files in different versions of Flash Player:
- In Flash Player 9.0.124.0 and later, a socket policy file is required for any Socket connection. That is, a socket policy file on the target host is required no matter what port you are connecting to, and is required even if you are connecting to a port on the same host that is serving the SWF file.
- In Flash Player versions 9.0.115.0 and earlier, if you want to connect to a port number below 1024, or if you want to connect to a host other than the one serving the SWF file, a socket policy file on the target host is required.
- In Flash Player 9.0.115.0, even if a socket policy file isn't required, a warning is displayed when using the Flash Debug Player if the target host doesn't serve a socket policy file.
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 related to security, see the following:
- The security chapter in the Programming ActionScript 3.0 book and the latest comments on LiveDocs
- The security chapter in the Programming ActionScript 3.0 book and the latest comments on LiveDocs
- The Flash Player Developer Center Topic: Security
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 | ||
timeout : uint
Indicates the number of milliseconds to wait for a connection. | Socket |
Method | Defined By | ||
---|---|---|---|
Creates a new 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 | ||
Dispatches an event into the event flow. | EventDispatcher | ||
Flushes any accumulated data in the socket's output buffer. | Socket | ||
Checks whether the EventDispatcher object has any listeners registered for a specific type
of event. | EventDispatcher | ||
Indicates whether an object has a specified property defined. | Object | ||
Indicates whether an instance of the Object class is in the prototype chain of the object specified
as the parameter. | Object | ||
Indicates whether the specified property exists and is enumerable. | Object | ||
Reads a Boolean value from the socket. | Socket | ||
Reads a signed byte from the socket. | Socket | ||
Reads the number of data bytes specified by the length
parameter from the socket. | Socket | ||
Reads an IEEE 754 double-precision floating-point number from the socket. | Socket | ||
Reads an IEEE 754 single-precision floating-point number from the socket. | Socket | ||
Reads a signed 32-bit integer from the socket. | Socket | ||
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 | ||
Reads a signed 16-bit integer from the socket. | Socket | ||
Reads an unsigned byte from the socket. | Socket | ||
Reads an unsigned 32-bit integer from the socket. | Socket | ||
Reads an unsigned 16-bit integer from the socket. | Socket | ||
Reads a UTF-8 string from the socket. | Socket | ||
Reads the number of UTF-8 data bytes specified by the length
parameter from the socket, and returns a string. | Socket | ||
Removes a listener from the EventDispatcher object. | EventDispatcher | ||
Sets the availability of a dynamic property for loop operations. | Object | ||
Returns the string representation of this object, formatted according to locale-specific conventions. | Object | ||
Returns the string representation of the specified object. | Object | ||
Returns the primitive value of the specified object. | Object | ||
Checks whether an event listener is registered with this EventDispatcher object or any of
its ancestors for the specified event type. | EventDispatcher | ||
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 | ||
Writes an IEEE 754 double-precision floating-point number to the socket. | Socket | ||
Writes an IEEE 754 single-precision floating-point number to the socket. | Socket | ||
Writes a 32-bit signed integer to the socket. | Socket | ||
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 | ||
Writes a 16-bit integer to the socket. | Socket | ||
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 | ||
Writes a UTF-8 string to the socket. | Socket |
Event | Summary | Defined By | ||
---|---|---|---|---|
[broadcast event] Dispatched when the Flash Player or 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 | |||
[broadcast event] Dispatched when the Flash Player or AIR application operating loses 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] Language Version: | ActionScript 3.0 |
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.
Implementation
public function get bytesAvailable():uint
connected | property |
connected:Boolean
[read-only] Language Version: | ActionScript 3.0 |
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.
Implementation
public function get connected():Boolean
endian | property |
endian:String
Language Version: | ActionScript 3.0 |
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.
Implementation
public function get endian():String
public function set endian(value:String):void
See also
objectEncoding | property |
objectEncoding:uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Controls the version of AMF used when writing or reading an object.
Implementation
public function get objectEncoding():uint
public function set objectEncoding(value:uint):void
See also
timeout | property |
timeout:uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | Flash Player 10, AIR 1.5 |
Indicates the number of milliseconds to wait for a connection.
If the connection doesn't succeed within the specified time, the connection fails. The default value is 20,000 (twenty seconds).
Implementation
public function get timeout():uint
public function set timeout(value:uint):void
Socket | () | Constructor |
public function Socket(host:String = null, port:int = 0)
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Creates a new 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.
Note: It is strongly advised to use the constructor form without parameters, then
add any event listeners, then call the connect
method with host
and port
parameters. This sequence guarantees that all event listeners will work
properly.
host:String (default = null ) — A fully qualified DNS domain name or an IP address in the form
111.222.333.444. In Flash Player 9.0.115.0 and AIR 1.0 and later,
you can specify IPv6 addresses, such as rtmp://[2001:db8:ccc3:ffff:0:444d:555e:666f].
You can also specify null to connect to the host server
on which the SWF file resides. If the SWF file issuing this call is running in a web browser,
host must be in the same domain as the SWF file.
| |
port:int (default = 0 ) — The TCP port number on the target host used to establish a connection.
In Flash Player 9.0.124.0 and later, the target host must serve a socket policy file
specifying that socket connections are permitted from the host serving the SWF file
to the specified port. In earlier versions of Flash Player, a socket policy file is required
only if you want to connect to a port number below 1024,
or if you want to connect to a host other than the one serving the SWF file.
|
Events
connect: — Dispatched when a network connection has been established.
| |
ioError: — Dispatched when an input/output error
occurs that causes the connection to fail.
| |
securityError: —
Dispatched if a call to Socket.connect() attempts
to connect either to a server that doesn't serve a socket policy file,
or to a server whose policy file doesn't grant the calling host access to the specified port.
For more information about socket policy files, see the "Flash Player Security" chapter in
Programming ActionScript 3.0.
|
Throws
SecurityError — This error occurs in SWF content
for the following reasons:
|
close | () | method |
public function close():void
Language Version: | ActionScript 3.0 |
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.
Throws
IOError — The socket could not be closed, or the socket was not open.
|
connect | () | method |
public function connect(host:String, port:int):void
Language Version: | ActionScript 3.0 |
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 or IP address 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.
|
Events
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
either to a server that doesn't serve a socket policy file,
or to a server whose policy file doesn't grant the calling host access to the specified port.
For more information,
see the "Flash Player Security" chapter in Programming
ActionScript 3.0.
|
Throws
IOError — No host was specified and the connection failed.
| |
SecurityError — This error occurs in SWF content
for the following reasons:
|
flush | () | method |
public function flush():void
Language Version: | ActionScript 3.0 |
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.
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
readBoolean | () | method |
public function readBoolean():Boolean
Language Version: | ActionScript 3.0 |
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 .
|
Throws
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 |
public function readByte():int
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads a signed byte from the socket.
Returnsint — A value from -128 to 127.
|
Throws
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 |
public function readBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
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 |
public function readDouble():Number
Language Version: | ActionScript 3.0 |
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.
|
Throws
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 |
public function readFloat():Number
Language Version: | ActionScript 3.0 |
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.
|
Throws
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 |
public function readInt():int
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads a signed 32-bit integer from the socket.
Returnsint — A value from -2147483648 to 2147483647.
|
Throws
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 |
public function readMultiByte(length:uint, charSet:String):String
Language Version: | ActionScript 3.0 |
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.
|
Throws
EOFError — There is insufficient data available to read.
|
readObject | () | method |
public function readObject():*
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads an object from the socket, encoded in AMF serialized format.
Returns* — The deserialized object
|
Throws
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 |
public function readShort():int
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads a signed 16-bit integer from the socket.
Returnsint — A value from -32768 to 32767.
|
Throws
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 |
public function readUnsignedByte():uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads an unsigned byte from the socket.
Returnsuint — A value from 0 to 255.
|
Throws
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 |
public function readUnsignedInt():uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads an unsigned 32-bit integer from the socket.
Returnsuint — A value from 0 to 4294967295.
|
Throws
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 |
public function readUnsignedShort():uint
Language Version: | ActionScript 3.0 |
Runtime Versions: | AIR 1.0 Flash Player 9 |
Reads an unsigned 16-bit integer from the socket.
Returnsuint — A value from 0 to 65535.
|
Throws
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 |
public function readUTF():String
Language Version: | ActionScript 3.0 |
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.
|
Throws
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 |
public function readUTFBytes(length:uint):String
Language Version: | ActionScript 3.0 |
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.
|
Throws
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 |
public function writeBoolean(value:Boolean):void
Language Version: | ActionScript 3.0 |
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 ).
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeByte | () | method |
public function writeByte(value:int):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeBytes | () | method |
public function writeBytes(bytes:ByteArray, offset:uint = 0, length:uint = 0):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeDouble | () | method |
public function writeDouble(value:Number):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeFloat | () | method |
public function writeFloat(value:Number):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeInt | () | method |
public function writeInt(value:int):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeMultiByte | () | method |
public function writeMultiByte(value:String, charSet:String):void
Language Version: | ActionScript 3.0 |
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 |
public function writeObject(object:*):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeShort | () | method |
public function writeShort(value:int):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeUnsignedInt | () | method |
public function writeUnsignedInt(value:uint):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
writeUTF | () | method |
public function writeUTF(value:String):void
Language Version: | ActionScript 3.0 |
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 that are 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.
|
Throws
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 |
public function writeUTFBytes(value:String):void
Language Version: | ActionScript 3.0 |
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.
|
Throws
IOError — An I/O error occurred on the socket, or the socket is not open.
|
See also
close | Event |
flash.events.Event
property Event.type =
flash.events.Event.CLOSE
Language Version: | ActionScript 3.0 |
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.Event
property Event.type =
flash.events.Event.CONNECT
Language Version: | ActionScript 3.0 |
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.IOErrorEvent
property IOErrorEvent.type =
flash.events.IOErrorEvent.IO_ERROR
Language Version: | ActionScript 3.0 |
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 (AIR only). |
target | The network object experiencing the input/output error. |
text | Text to be displayed as an error message. |
securityError | Event |
flash.events.SecurityErrorEvent
property SecurityErrorEvent.type =
flash.events.SecurityErrorEvent.SECURITY_ERROR
Language Version: | ActionScript 3.0 |
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.ProgressEvent
property ProgressEvent.type =
flash.events.ProgressEvent.SOCKET_DATA
Language Version: | ActionScript 3.0 |
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. |
- The constructor creates a
CustomSocket
instance namedsocket
and passes the host namelocalhost
and port 80 as arguments. SinceCustomSocket
extends Socket, a call tosuper()
calls Socket's constructor. - The example then calls the
configureListeners()
method, which adds listeners for Socket events. - Finally, the socket
connect()
method is called withlocalhost
as the host name and 80 as the port number.
Note: To run the example, you need a server running on the same domain
where the SWF resides (in the example, localhost
) and listening on port 80.
package { import flash.display.Sprite; public class SocketExample extends Sprite { public function SocketExample() { var socket:CustomSocket = new CustomSocket("localhost", 80); } } } import flash.errors.*; import flash.events.*; import flash.net.Socket; class CustomSocket extends Socket { private var response:String; public function CustomSocket(host:String = null, port:uint = 0) { super(); configureListeners(); if (host && port) { super.connect(host, port); } } private function configureListeners():void { addEventListener(Event.CLOSE, closeHandler); addEventListener(Event.CONNECT, connectHandler); addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); } private function writeln(str:String):void { str += "\n"; try { writeUTFBytes(str); } catch(e:IOError) { trace(e); } } private function sendRequest():void { trace("sendRequest"); response = ""; writeln("GET /"); flush(); } private function readResponse():void { var str:String = readUTFBytes(bytesAvailable); response += str; } private function closeHandler(event:Event):void { trace("closeHandler: " + event); trace(response.toString()); } private function connectHandler(event:Event):void { trace("connectHandler: " + event); sendRequest(); } private function ioErrorHandler(event:IOErrorEvent):void { trace("ioErrorHandler: " + event); } private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler: " + event); } private function socketDataHandler(event:ProgressEvent):void { trace("socketDataHandler: " + event); readResponse(); } }
Fri Mar 19 2010, 02:45 AM -07:00