A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: socket

  1. #1
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780

    socket

    Hi,

    Has anybody had any success in using AS3 socket, I have various ways of connecting and sometimes it does but closes automatically after a few seconds, I also get invalid socket after closing when trying to send message.

    I have tried with numerous ports and various combinations of the local, site, external etc ect.

    I never get the connected message whilst online

    PHP Code:
    import flash.net.Socket;
    import flash.events.*;

    var 
    socket:Socket = new Socket();
    var 
    port:Number80;

    var 
    site:String "fruitbeard.net";
    var 
    local:String "127.0.0.1";
    var 
    external:String "176.24.181.163";

    Security.allowDomain("*");
    Security.allowInsecureDomain("*");
    Security.loadPolicyFile("http://" site "/crossdomain.xml");
    //Security.loadPolicyFile("xmlsocket://" + local + ":" + String(port));

    socket.addEventListener(Event.CONNECTonConnect);
    socket.addEventListener(Event.CLOSEonClose);
    socket.addEventListener(IOErrorEvent.IO_ERRORonError);
    socket.addEventListener(ProgressEvent.SOCKET_DATAonResponse);
    socket.addEventListener(SecurityErrorEvent.SECURITY_ERRORonSecError);

    //socket.connect(site, port);
    //socket.connect(local, port);
    //socket.connect(external, port);
    socket.connect(siteport);

    function 
    onConnect(e:Event):void
    {
        
    //socket.writeUTFBytes("GET / HTTP/1.1\n");
        //socket.writeUTFBytes("Host: fruitbeard.net\n");
        //socket.writeUTFBytes("\n");
        
    socket.flush();
        
    chatArea.htmlText += "<u>Connected</u>\n<font color='#0066ff'>" e;
    }

    function 
    onClose(e:Event):void
    {
        
    socket.flush();
        
    socket.close();
        
        
    chatArea.htmlText += "<u><font color='#ff5500'>Disconnected</font></u>\n<font color='#0066ff'>" e;
    }

    function 
    onError(e:IOErrorEvent):void
    {
        
    trace("IO Error: " e);
        
    chatArea.htmlText += "<u><font color='#ff5500'>IO Error</font></u>\n<font color='#0066ff'>" e;
    }

    function 
    onSecError(e:SecurityErrorEvent):void
    {
        
    trace("Security Error: " e);
        
    chatArea.htmlText += "<u><font color='#ff5500'>Security Error</font></u>\n<font color='#0066ff'>" e;
    }

    function 
    onResponse(e:ProgressEvent):void
    {
        if (
    socket.bytesAvailable 0)
        {
            var 
    readMessage:String String(socket.readUTFBytes(socket.bytesAvailable));
            
    //trace(readMessage);
            
    chatArea.htmlText += readMessage;
            
    socket.flush();
            
    readMessage "";
        }
    }

    sendButt.addEventListener(MouseEvent.CLICKsendBytes);
    sendButt.buttonMode true;

    function 
    sendBytes(e:MouseEvent)
    {
        if (
    pMessage.text != "")
        {
            var 
    sendMessage:String pMessage.text "\r\n";
            
    //trace(sendMessage);
            
    socket.writeUTFBytes(sendMessage);
            
    sendMessage "";
            
    pMessage.text "";
        }

    and my crossdomain which is on the server is simply
    Code:
    <?xml version="1.0"?>
    <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
    <cross-domain-policy>
       <allow-access-from domain="*" to-ports="*" />
    </cross-domain-policy>
    any solutions most welcomed

    I beleive its probably the crossdomain / policy file, but I'm stuck as the errors whilst online are always 2048 security

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    I was playing with Socket and ServerSocket last year and achieve some cool things. But I prefer Yahoo's PlayerIO. Have you tested playerio already?

    Regards
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    My problem is my web host does not allow port binding with the current plan I have.
    I don't really actually need it and it was just for experiment, I do use smartfox on occasion.

    Thanks for the inputus.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center