XMLSocket
Encyclopedia
XMLSocket is a class in ActionScript
ActionScript
ActionScript is an object-oriented language originally developed by Macromedia Inc. . It is a dialect of ECMAScript , and is used primarily for the development of websites and software targeting the Adobe Flash Player platform, used on Web pages in the form of...

 which allows Adobe Flash
Adobe Flash
Adobe Flash is a multimedia platform used to add animation, video, and interactivity to web pages. Flash is frequently used for advertisements, games and flash animations for broadcast...

 content to use socket communication
Internet socket
In computer networking, an Internet socket or network socket is an endpoint of a bidirectional inter-process communication flow across an Internet Protocol-based computer network, such as the Internet....

, via TCP stream socket
Stream socket
In computer networking, a stream socket is a type of internet socket which provides a connection-oriented, sequenced, and unduplicated flow of data without record boundaries, with well-defined mechanisms for creating and destroying connections and for detecting errors.This internet socket type...

s. It can be used for plain text
Plain text
In computing, plain text is the contents of an ordinary sequential file readable as textual material without much processing, usually opposed to formatted text....

, although, as the name implies, it was made for XML
XML
Extensible Markup Language is a set of rules for encoding documents in machine-readable form. It is defined in the XML 1.0 Specification produced by the W3C, and several other related specifications, all gratis open standards....

. It is often used in chat applications and multiplayer games.

ActionScript 2.0

For a simple Hello, World! application in ActionScript 2.0, you could use the code below:


var xmlSocket:XMLSocket=new XMLSocket;
xmlSocket.onConnect=function {
xmlSocket.send(new XML("Hello, World!"));
}
xmlSocket.onXML=function(myXML) {
trace(myXML.firstChild.childNodes[2].firstChild.nodeValue);
xmlSocket.close;
}
xmlSocket.connect("localhost",8463);


This would result in the output window of the Flash IDE
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...

 opening and displaying "Hello, World!", assuming that a socket server was running on port 8463 of the local machine, and was echoing everything sent to it.

ActionScript 3.0

Simple connectivity for xmlSocket with ActionScript 3.0 as below:


var xml_s=new XMLSocket;
xml_s.connect(ip,port);
xml_s.addEventListener(Event.CONNECT,xmlsocket);
xml_s.addEventListener(Event.CLOSE,xmlsocket);
xml_s.addEventListener(IOErrorEvent.IO_ERROR,xmlsocket);

function xmlsocket(Event):void {
switch (Event.type) {
case 'ioError' :
//Unable to Connect
break;
case 'connect' :
//Connected
break;
case 'close' :
//OnDisconnect
break;
}
}


External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK