XML Sockets in Flash - Methods and Properties
(Page 2 of 5 )
I'll enumerate the different methods and properties that this object contains, and then explain common coding practices.
close() - This method allows you to cleanly terminate an open socket from the client's end of communication.
connect() - This method allows you to connect to a server running a socket server that is able to interpret the EOL character that is currently standard for Flash sockets (the ASCII null character, or '\0'). It will also eventually invoke the onConnect event-handler. This method accepts two parameters: a string as the URL of the server to connect to, and an integer as the port that the socket server is waiting on.
send() - This method allows you to send a string of characters through the socket connection. While the string is usually in XML format it does not have to be. This string can either be constructed using the XML object within Flash, or manually if size permits. Flash will also automatically append the terminating null character for you.
onConnect() - This event-handler is invoked either on success or failure for the connection attempt. It will return a Boolean based on the connections status (not to be confused with the 'status' property of a parsed XML object).
onXML() - This event-handler is invoked upon receipt of a null character. When this event is triggered the data that was received since the last null character has already been parsed, and placed into a hierarchy that you can use to retrieve the data – again using the XML object in Flash.
onData() - This event is similar to the onXML event, but it is triggered before any parsing. This allows for manual parsing or custom string handling (which can be quite useful as we’ll see near the end of this article).
onClose() - This event is not as intuitive as it might seem. It is triggered when the server terminates the connection - not when the client terminates. This is generally used to handle an unexpected disconnection from the server.
Next: Common Utilizations >>
More Flash Articles
More By Richard Lyman