0 Replies Latest reply on Dec 31, 2010 5:19 AM by Sarfraz07

    Datagram socket is not working

    Sarfraz07

      Hi,

      I made a datagram socket and try to send a byte array. but when I called socket.send method it returned an error that an operation is attempted on invalid socket. What I am missing

       

      here is my code...

       

      <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="480" height="262">

       

       

      <mx:Script><![CDATA[

       

       

       

      private var udp:DatagramSocket = new DatagramSocket();

      private var address:String = "255.255.255.255";

      private var port:uint = 200;

       

       

       

      private function OnSend():void

      {

        udp.addEventListener(DatagramSocketDataEvent.DATA, RecvUdpDataHandler);

        var byteArray:ByteArray = new ByteArray();

        byteArray.endian = Endian.LITTLE_ENDIAN;

        byteArray.writeMultiByte("dvcrNetshare", "US-ASCII");

        byteArray.writeUnsignedInt(123);

       

        udp.send(byteArray, 0, byteArray.length, address, port);

        udp.receive();

      }

       

       

      private function RecvUdpDataHandler(obj:DatagramSocketDataEvent):void

      {

        var str:String = obj.srcAddress;

        var srcport:int = obj.srcPort;

      }

       

       

      ]]></mx:Script>

       

      <mx:Button x="206" y="134" label="Send" click="OnSend()"/>

       

       

       

      </mx:WindowedApplication>

       

      Thanks