XMLsocket + localhost + FlashLite 2.1

Hi,
On FlashLite2.1, trivial XMLSocket code connecting to a
localhost
server fails in a strange manner:
- The server sees the connection as established
- But the onConnect callback never gets called
This happens only on the device (a WM5 Samsung i860
smartphone). Not
in Device Central.
This does not happen if the server is more "remote" (over USB
or
GPRS).
I suspect an issue with the speed of establishment of the
socket, a
kind of race condition in the implementation of
XMLsocket.connect().
The code, in the Actions of a single frame swf, is:
var sok:XMLSocket;
// do_connect is bound to a button press event
function do_connect()
sok=new XMLSocket();
sok.onConnect=function(){ /* set some dynamic text
variable */}
if (sok.connect("127.0.0.1",4444)) { /* do some other
visible effect */}
In the emulator it works like a charm. On the device,
sok.connect()
return true but the visible effect of onConnect (setting some
dynamic
text in the frame) never occurs !
Any idea ?
-Alex

quote:
Originally posted by:
Simon G.
quote:
Originally posted by:
Ben RB Chang
I've checked Jarpa today
. The key concept is:
we can use this code in j2me app to execute my flash lite
files.
midlet.platformRequest("file:///e:/others/xx
.swf")
But I meet another problem.
My default flash lite player on Nokia E70 is version 1.1.
Although I installed flash lite player 2
.1 and 3.0.
It still open my *.swf by 1
.1.
And then it will show me an error:
"Can't open file
. File is broken."
(The language of my phone is Chinese, it shows something like
that..
So, I must find out how to change the mapping between "mime
type" and "default app".
it still doesn't work but i think this idea is very close.
Still working on it...
Simon G.
I try to solve the same problem. In a Flash file I want to
load another textfile. So if I open the flash in the new player it
works, but if I open the flash directly from the memory card in
it's folder flash can't connect.
After java opns the flash-document and the player starts I
push 'Options' of the flash player and and go to "programm
information" ... but there it shows version 3 - the newest flash
player version?! But the connection doesn't work.

Similar Messages

  • Will FlashLite 3.0 support netconnection?

    Will FlashLite 3.0 support netconnection?
    As Flash Media Server does not support xmlsocket and
    FlashLite 2.1 does not support netconnection, we can't find a way
    for them to communicate with each other. we are so frustrating
    right now. Should we give up FMS and choose other socket server? Or
    should we give up FlashLite and just use Flash 9.0 for our mobile
    product?(We are developing game products for mobile device.)

    hi,
    as Adobe announced FL3.0 will support FLV, and to add FMS
    based FLV streaming, adobe have to implement netconnection. but we
    have to wait and see how the mobile implementation will work.
    // chall3ng3r //

  • Parse method of JAXP DocumentBuilder using InputStream

    I am having some problem. I am working on a generic XML messaging client server pair. The crux of it is that I am using the Transformer object to send data from the client to the server, using a Socket InputStream. The I do exactly the same from the server side to the client side.
    Example (client side):
    OutputStream out = socket.getOutputStream();
    Transformer transformer =
    TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(request),
    new StreamResult(out));
    Example (server side, in the thread for the connection):
    InputStream in = socket.getInputStream();
    DocumentBuilder builder =
    DocumentBuilderFactory.newInstance
    ().newDocumentBuilder();
    Document request = builder.parse(in);
    The problem I am experiencing is that the parse method on the server side is never completing. The parse method does not return at all. I can understand that this is due to the InputStream still being open, and need to know how can I let the parse method know that I am done writing to the OutputStream at the client side. Should I be sending an EOF character of sorts? If I should, what byte value represents this, and what do I need to do?
    Thank you
    Heinrich Pool

    Sorry hadn't noticed the Code Tags before. So the code formatted
    package de.gaskin.xml;
    import de.gaskin.buf.Buffer;
    import de.gaskin.io.LineArray;
    import de.gaskin.util.Debug;
    import java.net.Socket;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.io.PrintWriter;
    import java.io.ByteArrayOutputStream;
    import java.io.ByteArrayInputStream;
    import java.io.File;
    import java.util.Vector;
    import org.w3c.dom.Document;
    A Simple to use generic XML Document transfer based on sockets.
    <H2>Theory of Operation.</h2>
    <p>A client sends an array of lines (an XML document) prepended by a line
    that ONLY contains an integer (the number of lines in the document that
    follows).
    <p>The server reads the first line (so that it knows how many lines belong to
    the next document) it then reads the specified number of lines into memory and
    when all lines have been read in passes them (as an InputStream) to an
    XMLParser to produce an XML DOM that is made available through the<br>
    <code>getDocument()</code> method.
    <h2>API</h2>
    The API is very simple to use as the following templates demonstrate.
    <h3>Client</h3>
    <pre>
        public class MyXmlSocketClient extends XmlSocket {
           MyXmlSocketClient(String serverAddress, String fileName) {
              super(serverAddress, 4711);
              run(fileName);
    </pre>
    <h3>Server Worker</h3>
        <pre>
        public class MyXmlSocketServer extends XmlSocket {
           MyXmlSocketServer(Socket s) {
              super(s);
           public void run() {
              Document doc = getDocument();
              // Process document
        </pre>
    <h3>Server Listener</h3>
        <pre>
        public class MyXmlServer {
           ServerSocket ss;
           boolean      stop;
           MyXmlSocketServer() {
              stop = false;
              try {
                 ss = new ServerSocket(4711);
                 while (! stop) {
                    Socket s = ss.accept();
                    new Thread(new MyXmlServerSocket(s));
              catch (Exception x) {
                 x.printStackTrace();
        </pre>
    <P>Last updated 10th Jan 2001.
    @author  David. M. Gaskin.
    @version Version 1.0 Oct 2000
    @since    Version 1.0
    public class XmlSocket implements Runnable {
       final static boolean debug = false;
       protected BufferedReader  data;
      /* protected */ public PrintWriter     pw;
                 Socket          socket;
       public XmlSocket(String domain, int port) {
          try {
             socket = new Socket(domain, port);
             common(socket);
          catch (Exception x) {
    //       x.printStackTrace();
             throw new Error(x.toString());
       public XmlSocket(Socket s) {
          socket = s;
          common(s);
       void common(Socket s) {
          try {
             data = new BufferedReader(new InputStreamReader(s.getInputStream()));
             pw   = new PrintWriter(s.getOutputStream(), true);
          catch (Exception x) {
    //       x.printStackTrace();
             throw new Error(x.toString());
       public Document getDocument() {
          Document rc = null;
          try {
             String line = data.readLine();
             int    linesInDoc = Integer.parseInt(line.trim());
             if (linesInDoc != -1) {
                ByteArrayOutputStream os = new ByteArrayOutputStream();
                for (int i = 0;i < linesInDoc;i++) {
                   line = data.readLine();
                   System.out.println(line);
                   byte[] byteLine = line.getBytes();
                   os.write(byteLine, 0, byteLine.length);
    //          System.out.println("END");
                rc = XmlFactory.readIn(new ByteArrayInputStream(os.toByteArray()));
          catch (Exception x) {
             x.printStackTrace();
          return rc;
       public void run(Vector lines) {
          int loopCnt = lines.size();
          if (debug) {
             println("" + loopCnt);
             for (int i = 0;i < loopCnt;i++) {
                println((String)lines.elementAt(i));
    //       pw.flush();
             println("-1");
          else {
             pw.println("" + loopCnt);
             for (int i = 0;i < loopCnt;i++) {
                pw.println((String)lines.elementAt(i));
    //       pw.flush();
             pw.println("-1");
          pw.flush();
       void println(String s) {
          System.out.println(s);
          pw.println(s);
       public void run() {
          Debug.d(this, "run", "S H O U L D   N E V E R   B E   I N V O K E D");
       public void run(String filename) {
          Buffer[] input = LineArray.readIn(filename);
          send(input);
       public void run(File file) {
          Buffer[] input = LineArray.readIn(file.getAbsolutePath());
          send(input);
       void send(Buffer[] input) {
          int loopCnt = input.length;
          pw.println("" + loopCnt);
          for (int i = 0;i < loopCnt;i++) {
             pw.println(input.toString());
    pw.flush();
    pw.println("-1");
    pw.flush();
    public int getDocIdx(String[] roots, Document doc) {
    int rc = -1;
    String rootName = doc.getDocumentElement().getTagName();
    int loopCnt = roots.length;
    for (int i = 0;i < loopCnt;i++) {
    if (rootName.equals(roots[i])) {
    rc = i;
    break;
    if (rc < 0)
    System.out.println(rootName + " N O T F O U N D");
    return rc;
    public Socket getSocket() {
    return socket;
    For testing only
    public static void main(String[] args) {
    XmlSocket xmlS = new XmlSocket("localhost", 36);
    xmlS.getDocument();

  • Socket access policy under Vista

    Hi, for a long time I could easily make socket connections
    from my swf files tom simples java servers on various ports (swfs
    embeded from activex, for example). I used the simple python server
    policy file provided at this article to open the needed tcp ports
    to my flash applications.
    http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html
    This works ok on Windows XP machines, Flash player 9 or 10.
    However, no single Vista machine seems able to find the 843 port to
    load the policy file. I tried to use another server for the policy
    file, tried to use another port for the policy
    (Security.loadPolicyFile("xmlsocket://localhost:8008");) but
    nothing seems to work - I just can't make my flash applications
    connect on Windows Vista.
    Is this a known problem? What am I doing wrong?
    Thank you!

    I have finally solved it... it seems to be a problem with Windows Vista Firewall.
    The Phyton server proposed by Adobe does not work (it seems to be blocked even with the firewall disabled).
    Nevertheless, the Perl server works properly.

  • Sandbox Error Violation issue connecting from Flash Builder

    I am trying to walk through the Getting started tutorials on the adobe developer site. I am using Flash Builder and I created a Flex 4 project. Other than that I pretty much followed the tutorial steps. In the debugger I am getting the following. Anyone figure out how to fix this. I have tried adding a crossdomain.xml to the webroot of the blazeds server. Does not seam to help.
    Warning: Timeout on xmlsocket://localhost:27813 (at 3 seconds) while waiting for socket policy file.  This should not cause any problems, but see http://www.adobe.com/go/strict_policy_files for an explanation.
    Error: SWF from http://localhost:8400/samples/blaze-tutorial-debug/main.swf may not connect to a socket in its own domain without a policy file.  See http://www.adobe.com/go/strict_policy_files to fix this problem.
    *** Security Sandbox Violation ***
    Connection to localhost:27813 halted - not permitted from http://localhost:8400/samples/blaze-tutorial-debug/main.swf

    Hi. Did you try asking about this problem on the FlashBuilder forum? I don't think this is related to BlazeDS.
    BlazeDS wouldn't be trying to connect to a local socket. Also, adding a crossdomain.xml file to the BlazeDS server wouldn't help with this as the player is not trying to connect to the BlazeDS server but to a local socket.
    Is the NetworkMonitor in FlashBuilder running? If I had to make a guess, I would say that maybe the NetworkMonitor is listening on that port and the player is trying to connect to the network monitor.
    You might need to do something in FlashBuilder to allow the player to connect to the socket. Someone on the FlashBuilder forum should be able to help you.
    -Alex 

  • Socket and Security Policy

    I've tried to set experiment with Socket communication in Flex, but I keep hitting problems. Approach 1: in a Flex web app, I load a crossdomain security policy from a server. I then open a socket and write a few bytes to the server. In my server, I do not get the expected output on the stream--in fact, I get nothing at all--until I close the Flex application, at which point I get a seemingly inifinite stream of the bytes '0xEFBFBF'. Here's a hexdump view of a fragment of the data Flash Player sends to the server after I close the Flex app:
    00000130  ef bf bf ef bf bf ef bf  bf ef bf bf ef bf bf ef  |................|
    00000140  bf bf ef bf bf ef bf bf  ef bf bf ef bf bf ef bf  |................|
    00000150  bf ef bf bf ef bf bf ef  bf bf ef bf bf ef bf bf  |................|
    Approach 2: I then tried it in air, but although the connection seems to initiate properly and I can go through the above trivial client-server interaction, after a few seconds, I get a SecurityErrorEvent. From what I've been able to follow of the docs, Air applications are trusted in this respect, and should not need to load security policy, right? I tried to add a call to Security.loadPolicy(), but it seems to be ignored. This is the message flow:
    Received [class Event] connect
    Received [class ProgressEvent] socketData
    Received [class Event] close
    Received [class SecurityErrorEvent] securityError
    Security error: Error #2048: Security sandbox violation: app:/main.swf cannot load data from localhost:5432.
    The Air version of my client code is below:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <mx:Script>
        <![CDATA[
            var str:Socket;
            private function handleClick(e:Event):void {
                Security.loadPolicyFile("xmlsocket://localhost:2525");           
                str = new Socket('localhost', 5555);
                var message:String = 'hello';
                for (var i:int = 0; i < message.length; i++) {
                    str.writeByte(message.charCodeAt(i));               
                str.writeByte(0);
                str.flush();
                str.addEventListener(Event.ACTIVATE, handleEvent);
                str.addEventListener(Event.CLOSE, handleEvent);
                str.addEventListener(Event.CONNECT, handleEvent);
                str.addEventListener(Event.DEACTIVATE, handleEvent);
                str.addEventListener(IOErrorEvent.IO_ERROR, handleEvent);
                str.addEventListener(ProgressEvent.SOCKET_DATA, handleEvent);
                str.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleEvent);           
            private function handleEvent(e:Event):void {
                 trace("Received", Object(e).constructor, e.type);
                 if (e is ProgressEvent) {
                     var strBytes:Array = [];
                     while(str.bytesAvailable > 0) {
                         var byte:int = str.readByte();
                         strBytes.push(byte);
                     trace(String.fromCharCode.apply(null, strBytes));
                 } else if (e is SecurityErrorEvent) {
                     trace("Security error:", SecurityErrorEvent(e).text);
        ]]>
    </mx:Script>
    <mx:Button label="test" click="handleClick(event)"/>   
    </mx:WindowedApplication>
    The server is in Java and is as follows:
    import java.net.*;
    import java.io.*;
    public class DeadSimpleServer implements Runnable {
        public static void main(String[] args) throws Exception {
            if (args.length != 2) {
                throw new Exception("Usage: DeadSimpleServer policy-port service-port");
            int policyPort = Integer.parseInt(args[0]);
            int servicePort = Integer.parseInt(args[1]);
            new Thread(new DeadSimpleServer(policyPort,
                                            "<?xml version=\"1.0\"?>\n" +
                                            "<cross-domain-policy>\n" +
                                            "<allow-access-from domain=\"*\" to-ports=\"" + servicePort + "\"/>\n" +
                                            "</cross-domain-policy>\n"
                       ).start();
            new Thread(new DeadSimpleServer(servicePort, "world")).start();
            while (true) Thread.sleep(1000);
        private int port;
        private String response;
        public DeadSimpleServer(int port, String response) {
            this.port = port;
            this.response = response;
        public String getName() {
            return DeadSimpleServer.class.getName() + ":" + port;
        public void run() {
            try {
                ServerSocket ss = new ServerSocket(port);
                while (true) {
                    Socket s = ss.accept();
                    System.out.println(getName() + " accepting connection to " + s.toString());
                    OutputStream outStr = s.getOutputStream();
                    InputStream inStr = s.getInputStream();
                    int character;
                    System.out.print(getName() + " received request: ");
                    while ((character = inStr.read()) != 0) {
                        System.out.print((char) character);
                    System.out.println();
                    Writer out = new OutputStreamWriter(outStr);
                    out.write(response);
                    System.out.println(getName() + " sent response: ");
                    System.out.println(response);
                    System.out.println(getName() + " closing connection");
                    out.flush();
                    out.close();
                    s.close();
            } catch (Exception e) {
                System.out.println(e);
    Am I missing something? From what I understand, either of these approaches should work, but I'm stuck with both. I have Flash Player 10,0,15,3 and am working with Flex / Air 3.0.0 under Linux.

    So... apparently, with the Air approach, this is what I was missing: http://www.ultrashock.com/forums/770036-post10.html
    It'd be nice if FlashPlayer gave us a nicer error here.
    I'm still trying to figure out what the heck is going on in the web app (i.e., non-Air Flex) example. If anyone has any suggestions, that would be very helpful.

  • CrossDomain  loadPolicyFile player 9.0.124

    System.security.loadPolicyFile("xmlsocket://localhost:843")
    this command line worked fine until I upgrade my player to
    version 9.0.124
    Now it doesn't work at all !!

    Thank you but that's OK now.
    I just forgot to close the "crossDomain" server socket
    connexion on port 843.

  • XMLSocket to localhost problem

    Hello!
    Doe anyone have experience with XMLSockets that have to connect to the localhost (or 127.0.0.1)?
    My flash application can connect to all other servers but not to the server the flash app resides on.
    The server accepts the socket but in flash the onConnect event has "false" as parameter. If I ignore this and start sending anyway, sometimes the data is send to the server.
    I run windows CE6.0 R3 with flash lite 3.1.
    Any Idea's?
    Thanks,
    John.

    Hi,
    don't know if it helps still, but i am using XMLSocket on Symbian: my FlashLite code accesses an natice C++ http server, using XMLSOckets.
    It works quite well, however i had some small tunings to do:
    * XML form (the one which is sent over to the server) has to terminate by '\0'. My code is adding an addtioanla '\0\ at the end, both on the FL code and on the server code
    * Of course, you have to publish your FL as "netwrok access"
    * .... and also to solve all the security problems (i.e. either crossdomain, or using Trusted subdir).
    Voila, not sure how much of ti applies to your plateform !
    Jacques.

  • Something is wrong with XMLsocket

    alright , I am using XMLsocket class, actrionscript 2.0
    (flash 8). I have set up appache server on port 1024, and I can
    connect without problems. But something's wrong with sending test
    data (I am using log file to check for incoming server requests)
    the code is this:
    quote:
    var theSocket:XMLSocket = new XMLSocket();
    theSocket.connect("localhost", 1024);
    theSocket.onConnect = function(myStatus) {
    if (myStatus) {
    TraceTxt("connection successful");
    } else {
    TraceTxt("no connection made");
    theSocket.onClose = function () {
    trace("Connection to server lost.");
    function sendData() {
    var myXML:XML = new XML();
    var mySend = myXML.createElement("thenode");
    mySend.attributes.myData = "someData";
    myXML.appendChild(mySend);
    theSocket.send(myXML);
    TraceTxt("I am trying to send: " + myXML);
    sendButton.onRelease = function() {
    sendData();
    theSocket.onData = function(msg:String):Void {
    trace(msg);
    function TraceTxt(strMessage:String)
    dtxMessage.text = dtxMessage.text + strMessage + "\n";

    Hello Alana,
    Do these songs/tracks sound okay in iTunes?  Have you tried resetting your iPod to see if that makes a difference?  To do this, press and hold both the Select (Center) and Menu buttons together until the Apple logo appears. 
    I would also try a different set of headphones/earbuds to see if that makes a difference as well.
    And if the problem still continues, try restoring your iPod via iTunes and reloading all your music back over to it.
    The last you may want to consider doing, if nothing from above resolves the issue is to rerip these tracks into iTunes.  Try importing them in a different format or at a different bit rate to see if that makes a difference.
    B-rock

  • Help! Flash MX to Labview with XMLsocket problem

    I'm attempting to send strings to Labview using the XMLsocket object
    in Macromedia Flash MX. I created a layer in Flash with the following
    Action script:
    mySocket = new XMLsocket();
    mySocket.connect("localhost",2055);
    Then I created a layer with a button that has the following button
    Action script:
    on (release) {
    mySocket.send("mystring");
    Then I created a Labview program (on the same machine) that has a
    single while loop with code that creates a listener at port 2055 (the
    port connected to Flash) and some code for reading the port.
    This setup works, except Labview will only receive the string once
    from the button push, even though the receive code is in a loop.
    Subsequent button pushes in Flash does not resul
    t in characters being
    received in LV. Has anyone here done this before? Thanks.
    gm

    Fixed it. You've got to have the Labview create listener VI started
    first and also outside the while loop. Works great!
    [email protected] (greenman) wrote in message news:<[email protected]>...
    > I'm attempting to send strings to Labview using the XMLsocket object
    > in Macromedia Flash MX. I created a layer in Flash with the following
    > Action script:
    >
    > mySocket = new XMLsocket();
    > mySocket.connect("localhost",2055);
    >
    > Then I created a layer with a button that has the following button
    > Action script:
    >
    > on (release) {
    > mySocket.send("mystring");
    > }
    >
    >
    > Then I created a Labview program (on the same machine) that has a
    > single while loop with code that creates a listener at port 2055 (the
    > port connected to
    Flash) and some code for reading the port.
    >
    > This setup works, except Labview will only receive the string once
    > from the button push, even though the receive code is in a loop.
    > Subsequent button pushes in Flash does not result in characters being
    > received in LV. Has anyone here done this before? Thanks.
    >
    > gm

  • XmlSocket.onXML and xmlSocket.onData problem

    Hi,
    I am having a problem with reading information that is being passed from a C# server. When I use xmlSocket.onXML, the xml object being passed from the server does not have any elements at all. When I use xmlSockt.onData, I am able to get the following output with tace:
    <?xml version="1.0"?>
    <Packet xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <UserID>5555</UserID>
      <UserName>Success</UserName>
      <Operation>RefreshUsers</Operation>
    </Packet>
    However, when I check the string variable that I used to store this string in debug mode, the value of the string is "". And when I try to create an XML object using var my_xml:XML = new XML(srcstring); I get the same problem as when I used the xmlSocket.onXML method. The xml object my_xml contains no elements at all.
    Can anyone help me out on this? Thank you.

    So I switched from XMLSocket to just plain Socket.
    I have this now:
      var sock:Socket = new Socket();
                sock.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
                sock.connect("localhost", 7778);
                sock.writeUTFBytes(xmlMsg);
                sock.flush();
    But nothing gets transmitted unless I close the Flex app.
    I don't get this. What seems to be a problem?
    I read an API docs twice and it says that writeUTFBytes (or any other write methods) are just putting stuff in a buffer
    the flush() is the one that signals that the buffer content needs to be sent.
    I'm doing just that and still I get nothing on the other side unless I close the Flex app.
    Any suggestion?
    Thanks
    Greg

  • XMLSocket onData Issue

    I am trying to narrow down a bug in an application that
    utilizes the XMLSocket class. I have reduced it to the following
    code below. Is there such a scenario that practically simultaneous
    messages sent from a server would cause 'false' to be traced more
    than once (ie. can the code in the onData method evaluate test as
    false more than once because onData is called a second time before
    the first onData method has had time to update test to true)? Can
    the onData method be treated as atomic? To a certain degree....?
    At the root of this question, I am trying to grasp how
    asynchronous calls are handled/queued to make sure I understand
    them correctly and prevent certain cases where a single-time
    operation may occur twice. If any one can help or direct me to
    information regarding this, I would be very thankful.
    Dan

    Hi Tracy,
    Thanks for your reply.
    SocketComm is a action script class which maintains XMLSocket
    object for the whole application.
    package asclasses
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.XMLSocket;
    import mx.controls.Alert;
    public class SocketComm extends Sprite
    private var hostName:String = "localhost";
    private var port:uint = 8080;
    private var socket:XMLSocket;
    public function createSocketConnection(hostName:String,
    port:uint):XMLSocket {
    if(socket == null) {
    socket = new XMLSocket();
    socket.connect(hostName, port);
    }else if(socket != null && !socket.connected) {
    socket.connect(hostName, port);
    return socket;
    Actually now i am able to communicate with server over
    XMLSocket.
    There was some problem at server side.
    But still i am not comfortable with using
    SocketComm(XMLSocket) as a common utility class due to event based
    asynchronus model. Like in Java Socket all calls are synchronus, I
    can easily create common class for socket communication.
    But due to my unfamiliarity with event based asynchrous model
    of programming, I am facing difficulties.
    Like my requirement is to use SocketComm class as a
    communication medium with server for various business operations
    like add, modify and delete etc. from various Flex UI screens. But
    due to event based model, I am not really sure how and when socket
    is going to send response.
    So if you look at my first post, I have added all listeners
    to mxml page but i feel this is not a good design, As i have
    atleast 4-5 mxml pages where in I will repeat these listeners.
    I would really appreciate if you could provide me some
    guidance on using SocketComm class as a effective common class.
    Thanks in advance :)
    Regards
    Tarun

  • XMLSocket Issue

    HI,
    I have written a small program which uses XMLSocket to
    communicate with some server.
    It works for the first time, I mean when i send first
    message, I got the response from server but after that flex client
    does not send any message to server and i see no exception in the
    code.
    can anybody pls. help ?
    Following is the code:
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute" width="800" height="600">
    <mx:TraceTarget level="0" />
    <mx:Script>
    <![CDATA[
    import asclasses.SocketComm;
    import flash.system.Security;
    import asclasses.ACTURLLoader;
    import mx.controls.Alert;
    import mx.rpc.events.ResultEvent;
    import mx.rpc.events.FaultEvent;
    import mx.rpc.http.HTTPService;
    private var response:String;
    private var socketComm:SocketComm;
    private var sock:XMLSocket;
    private var isSocketConnected:Boolean = false;
    private function handleTest():void {
    // Printing Sandbox
    var sandbox:String = Security.sandboxType;
    sandboxType.text = sandbox;
    if(!isSocketConnected) {
    // Local Windows Service
    var host:String = winServiceHost.text;
    var port:String = winServicePort.text;
    socketComm = new SocketComm();
    sock = socketComm.createSocketConnection(host, int(port));
    configureSocketListeners(sock);
    }else {
    Alert.show("Entered in else part");
    if(sock.connected) {
    Alert.show("socket is connected");
    try {
    sock.send(msg.text+"\n");
    }catch(ie:IOError) {
    Alert.show(ie.toString());
    }else {
    Alert.show("sock is not conected");
    private function
    configureSocketListeners(dispatcher:IEventDispatcher):void {
    dispatcher.addEventListener(Event.CLOSE, socketHandler);
    dispatcher.addEventListener(Event.CONNECT, socketHandler);
    dispatcher.addEventListener(DataEvent.DATA, socketHandler);
    dispatcher.addEventListener(ErrorEvent.ERROR,
    socketHandler);
    dispatcher.addEventListener(SecurityErrorEvent.SECURITY_ERROR,
    socketHandler);
    dispatcher.addEventListener(IOErrorEvent.IO_ERROR,
    socketHandler);
    dispatcher.addEventListener(ProgressEvent.SOCKET_DATA,
    socketHandler);
    private function socketHandler(event:Event):void {
    var socket:XMLSocket = XMLSocket(event.target);
    Alert.show(event.toString());
    trace(event.toString());
    if(event.type == Event.CLOSE) {
    winServiceContent.text = response;
    }else if(event.type == SecurityErrorEvent.SECURITY_ERROR) {
    socket.close();
    }else if(event.type == IOErrorEvent.IO_ERROR) {
    socket.close();
    }else if(event.type == DataEvent.DATA) {
    winServiceContent.text += DataEvent(event).data;
    }else if(event.type == Event.CONNECT) {
    // Sending first msg
    Alert.show("Sending Message : " + msg.text);
    socket.send(msg.text+"\n");
    isSocketConnected = true;
    }else if(event.type == ProgressEvent.SOCKET_DATA) {
    trace("progressHandler loaded:" +
    ProgressEvent(event).bytesLoaded + " total: " +
    ProgressEvent(event).bytesTotal);
    ]]>
    </mx:Script>
    <mx:Form id="fff" x="36" y="10" width="500"
    height="414">
    <mx:FormHeading label="Security Test Form"/>
    <mx:FormItem label="Sandbox Type">
    <mx:Text id="sandboxType"/>
    </mx:FormItem>
    <mx:FormItem label="Windows Service Host">
    <mx:TextInput id="winServiceHost"
    text="10.201.205.196"/>
    </mx:FormItem>
    <mx:FormItem label="Windows Service Port">
    <mx:TextInput id="winServicePort" text="8081"/>
    </mx:FormItem>
    <mx:FormItem label="Command Message">
    <mx:TextInput id="msg" />
    </mx:FormItem>
    <mx:FormItem label="Windows Service Content">
    <mx:TextArea id="winServiceContent"/>
    </mx:FormItem>
    </mx:Form>
    <mx:Button label="Test" click="handleTest()" x="54"
    y="452"/>
    <mx:Button label="Clear" x="132" y="452" />
    </mx:Application>

    Hi Tracy,
    Thanks for your reply.
    SocketComm is a action script class which maintains XMLSocket
    object for the whole application.
    package asclasses
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.XMLSocket;
    import mx.controls.Alert;
    public class SocketComm extends Sprite
    private var hostName:String = "localhost";
    private var port:uint = 8080;
    private var socket:XMLSocket;
    public function createSocketConnection(hostName:String,
    port:uint):XMLSocket {
    if(socket == null) {
    socket = new XMLSocket();
    socket.connect(hostName, port);
    }else if(socket != null && !socket.connected) {
    socket.connect(hostName, port);
    return socket;
    Actually now i am able to communicate with server over
    XMLSocket.
    There was some problem at server side.
    But still i am not comfortable with using
    SocketComm(XMLSocket) as a common utility class due to event based
    asynchronus model. Like in Java Socket all calls are synchronus, I
    can easily create common class for socket communication.
    But due to my unfamiliarity with event based asynchrous model
    of programming, I am facing difficulties.
    Like my requirement is to use SocketComm class as a
    communication medium with server for various business operations
    like add, modify and delete etc. from various Flex UI screens. But
    due to event based model, I am not really sure how and when socket
    is going to send response.
    So if you look at my first post, I have added all listeners
    to mxml page but i feel this is not a good design, As i have
    atleast 4-5 mxml pages where in I will repeat these listeners.
    I would really appreciate if you could provide me some
    guidance on using SocketComm class as a effective common class.
    Thanks in advance :)
    Regards
    Tarun

  • XMLSocket Problem

    I can work fine which run in flash . I can see the connection can established and disconnected until i close the flash
    but i publish the flash to html and run in broswer, the flash can connect to server but it will disconnected in the same time. That means i can see the log is established connection then disconnect connnection.
    I cannot find the solution.
    Please help.
    Thank you
    flash code :
    mySocket = new XMLSocket();
    mySocket.onConnect = function(success) {
        if (success) {
            msgArea.htmlText += "<b>Server connection established!</b>";
        } else {
            msgArea.htmlText += "<b>Server connection failed!</b>";
    mySocket.onClose = function() {
        msgArea.htmlText += "<b>Server connection lost</b>";
    XMLSocket.prototype.onData = function(msg) {
        msgArea.htmlText += msg;
    mySocket.connect("dyn.obi-graphics.com", 9999);
    //--- Handle button click --------------------------------------
    function msgGO() {
        if (inputMsg.htmlText != "") {
            mySocket.send(inputMsg.htmlText+"\n");
            inputMsg.htmlText = "";
    pushMsg.onRelease = function() {
        msgGO();

    So I switched from XMLSocket to just plain Socket.
    I have this now:
      var sock:Socket = new Socket();
                sock.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
                sock.connect("localhost", 7778);
                sock.writeUTFBytes(xmlMsg);
                sock.flush();
    But nothing gets transmitted unless I close the Flex app.
    I don't get this. What seems to be a problem?
    I read an API docs twice and it says that writeUTFBytes (or any other write methods) are just putting stuff in a buffer
    the flush() is the one that signals that the buffer content needs to be sent.
    I'm doing just that and still I get nothing on the other side unless I close the Flex app.
    Any suggestion?
    Thanks
    Greg

  • XMLSocket on Windows Mobile - no data send and onConnect not entered

    Hi,
    I'm developing a FlashLite 2.1 application and try to communicat with the host device (WiMo) through a XMLSocket to write some data to the disk.
    I have the following code in the FL-App:
    xmlSocket = new XMLSocket();
    xmlSocket.onConnect = function(success:Boolean)
              fscommand("Launch", "\\...\\FileEditor.exe,Success=" + success);
              if (success)
                   LearnLogic.Current.xmlSocket.send(LearnLogic.Current.Message.toString());
              else
                   LearnLogic.Current._cardBox[_cardIds[_currentCardIndex]] = 10;
    var connected:Boolean = xmlSocket.connect("127.0.0.1", 8181);               
    fscommand("Launch", "\\...\\FileEditor.exe,Connected=" + connected);
    xmlSocket.send(Message.toString());
    xmlSocket.close();
    The File Editor simply writes the Argument to a log file and I get the "Connected=true" in the log, but not the "Success=xxx" and on the host application (C#) I got a connection but no data is submitted (Client.Available stays 0).
    What can I do to fix that problem or is there an easier way to edit files on the phone?
    regards

    Hi,
    my file editor is a console application, so it has no window which can come to the foreground and I already have a Launch command inside the onConnect Handler which get never called (=no etry in the log file)...
    regards

Maybe you are looking for

  • Microsoft Word 2008 Spacing

    I know this probably isnt the "right" place for this question but Microsoft support forums are terrible so maybe someone here can help me. I have Microsoft Office 2008 and I the spacing between lines is too large, so I go to paragraph formatting and

  • Top part of MSN homepage is not displaying. Works in Chrome.

    Today, for the first time, the top of the MSN homepage is not displaying. It cuts off just below the top of the 9 scrolling windows. Thought it may be an MSN problem, so I opened up MSN in Chrome and works fine. Cleared cache and still not working. A

  • Inactive connection in update rules

    Hello, How do I update my update rules for 0MATERIAL_ATTR in the production system (BW prod)? I have attempted to transport the update from dev. I have the info object in the uodate rules, but not the connection to the source field. How do I get the

  • How to work with HR forms

    Hi,          i am new to HR Forms & Payroll Reporting. any one, pls send me step by step procedure for HR forms. I have gone through PE51 , how to connect the data to form.its really urgent.as i need to develop forms in 4.6C. thanku.

  • How to burn a Video CD?

    Hey all! I downloaded few videos which are in Real Player format. I want to burn these on a CD and view it on big screen. I copied and pasted them on a CD and played it in my CD player but its not working. Also, what do I do for burning a video DVD?