I am flex newbie and I am trying to get the example given here :http://livedocs.adobe.com/flex/3/html/help.html?content=17_Networking_and_communications_5.html
I am using the same java server given there. and I am creating the XmlSocket in a flex air application. When I run my air application I get a java.net.SocketException connection reset at the java server.
Both are stand alone applications on my desktop.
Flex Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="init()">
    <mx:Script>
        <![CDATA[
        import mx.controls.Alert;
        public function init():void
        {
            var xmlsock:XMLSocket = new XMLSocket();
            //xmlsock.addEventListener(DataEvent.DATA, onData);
            xmlsock.addEventListener(Event.CLOSE, onData);
            xmlsock.addEventListener(Event.CONNECT, onData);
            xmlsock.addEventListener(DataEvent.DATA, onData);
            xmlsock.addEventListener(IOErrorEvent.IO_ERROR, onData);
            xmlsock.addEventListener(ProgressEvent.PROGRESS, onData);
            xmlsock.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onData);
            xmlsock.connect("localhost", 9020);
            //xmlsock.send("<hello></hello>");
        }
        private function onData(event:Event):void
        {
             myText.text=""+event.toString();
        }
            ]]>
    </mx:Script>
    <mx:Panel>
        <mx:TextArea id="myText">
        </mx:TextArea>
    </mx:Panel>
</mx:WindowedApplication>
Java Code:
import java.io.*;
import java.net.*;
class SimpleServer
{
    private static SimpleServer server;
    ServerSocket socket;
    Socket incoming;
    BufferedReader readerIn;
    PrintStream printOut;
    public static void main(String[] args)
    {
        int port = 9020;
        try
        {
            port = Integer.parseInt(args[0]);
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            // Catch exception and keep going.
        }
        server = new SimpleServer(port);
    }
    private SimpleServer(int port)
    {
        System.out.println(">> Starting SimpleServer");
        try
        {
            socket = new ServerSocket(port);
            incoming = socket.accept();
            readerIn = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
            printOut = new PrintStream(incoming.getOutputStream());
            printOut.println("Enter EXIT to exit.\n\0");
            out("Enter EXIT to exit.\r");
            boolean done = false;
            while (!done)
            {
                String str = readerIn.readLine();
                if (str == null)
                {
                    done = true;
                }
                else
                {
                    out("Echo: " + str + "\r");
                    if(str.trim().equals("EXIT"))
                    {
                        done = true;
                    }
                }
                incoming.close();
            }
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }
    private void out(String str)
    {
        printOut.println(str);
        System.out.println(str);
    }
}
Thanks a lot in advance..