Project site
A javascript interface to Adobe Flash's XMLSocket class
Last commit
11 years ago
MIT License
Last release
11 years ago



jsXMLSocket allows you to do asynchronous communication with a server using Adobe Flash's XMLSocket class. The XMLSocket class allows you to send and receive null terminated messages. Contrary to what the name indicates jsXMLSocket can be used for sending any type of data as long as the messages are null terminated.

jsXMLSocket is based off jSocket which implements a more general access to sockets in javascript using Flash's Socket class. In many implementations jSocket can be unnecessarily complicated and slower than jsXMLSocket.


jsXMLSocket works in an object oriented fashion around the jsXMLSocket object. Before loading jsxmlsocket.js you must have loaded jQuery.

The jsXMLSocket Object



Contructor of the jXMLSocket Object.



Call this method to setup the socket. jsXMLSocket.setup takes the required argument target, which should contain a jQuery Selector that points to a container where jSocket will place the flash file in. After the DOM has updated and the flash file has loaded, it will fire jsXMLSocket.onReady.

jsXMLSocket.connect(host, port)

Call this method to connect to a listening socket. Method takes two required arguments, host which should be a host name or a valid ip address to connect to, and port to indicate which port we are connecting on, Flash requires us to use ports above 1024 for security reasons. Once the connection process has finished it will fire jsXMLSocket.onConnect.


Call this method to close the socket connection. It's important to know that this will not trigger the jsXMLSocket.onClose event.


Call this method to send the data in data. jsXMLSocket.send(data) will null terminate the data.



Called by the socket when socket is ready for use.


Called by the socket when socket has finished connecting. success will either be true when the connection is estabilished or false when it failed. error will contain the error text when the connection fails.


Called by the socket when socket has received a null terminated message. data will contain the received data.


Called by the socket when socket has been closed on the other side.


    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="jsxmlsocket.js"></script>
    <script type='text/javascript'>
        // Host we are connecting to
        var host = 'localhost';
        // Port we are connecting on
        var port = 8008;

    var socket = new jsXMLSocket();

    // When the socket is added the to document
    socket.onReady = function() {
        socket.connect(host, port);
        $('#messages').append('Connecting to ' + host + ':' + port + '... ');

    // Connection attempt finished
    socket.onConnect = function(success, error) {
        if(success) {
        } else {
            $('#messages').append('Connection failed.&lt;br/&gt;');

    // Server closed socket
    socket.onClose = function() {
        $('#messages').append('Server disconnected.&lt;br/&gt;');

    // Received data
    socket.onData = function(data) {
        $('#messages').append(data + '&lt;br/&gt;');

    $(document).ready(function() {
        // Setup our socket in the div with the id="socket"

</head> <body> <div id='socket'></div> <h1>jsXMLSocket</h1> <div id="messages"></div> </body> </html>

Adobe Flash security

Adobe Flash imposes security restrictions on socket access. To be able to use sockets in Flash the swf file must have been loaded from a webserver and not the local filsystem using a file:// url. Additionally the server you are connecting to must grant access to Flash before you can connect. This is done by sending a socket policy file in response to receiving a policy file request at port 843 or at the port you are trying to connect to. See Adobe's documentation on the Flash security restrictions.

Example socket policy for testing purposes:

<?xml version="1.0" encoding="UTF-8" ?> 
<cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd">
    <allow-access-from domain="" to-ports="" secure="false" /> 
    <site-control permitted-cross-domain-policies="master-only" /> 


jsXMLSocket consists of only two source files: the Actionscript file jsxmlsocket.as and the javascript file jsxmlsocket.js. It is only necessary to change these two files to fix bugs and add functionality.

To compile a new swf file after modifying jsxmlsocket.as you need the Adobe Flex 3 SDK, then simply type:

mxmlc jsxmlsocket.as

Social media

  • delicious 11
  • ff_comments 1
  • twitter 9

Latest releases

You might also like...


Source Code Commits

  • 2. Initial checkin (11 years ago)
  • 2. Initial checkin (11 years ago)
  • 2. Initial checkin (11 years ago)
  • 2. Initial checkin (11 years ago)
  • 2. Initial checkin (11 years ago)


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin.” - John von Neumann