1 Reply Latest reply: Jan 17, 2012 5:40 PM by Mhood89 RSS

    Client - Server socket in AS3

    Mhood89

      hi every body

       

      i just wana an exiplinantion about socket in AS3

      this a java code for socket communication

       

      Server Side
      Client Side

       

      serversocket s  = new ServerSocket("ip",port);

      Socket client;

      while (true)

      {

      client = s.accept();

      DataInptStream d =client.get ...etc

      DataOutptStrm o=client.getoutpt....etc

      read

      write methods

      }

      Socket client=new socket(port);

      Dataoutptstrm SendtoServer=client.getoutpt...

      .

      .

      .

      etc

       

       

      i asked for an implementation for that , i read about but i couldn't understand how could it be

      also if i have a java listeneer on a port,, could as3 socket connect to that port, i ment does dataoutpt streams in java will work with as3 sockets???

        • 1. Re: Client - Server socket in AS3
          Mhood89 Community Member

          hi again

          in AS3 we cannot build a server but i build a client

           

          a java server runs above

          and the client in AS3 is :

           

           

          var client:socket=new socket();

          client.connect("localhost",port);

           

          client.addeventlistener(progressevent.socket_data,read);

          function read(e:progressevent):void{

          var t:string=e.readutf();

           

          }

           

          function snd(String tt){

          if(Client.isconnected){

          client.writeutf(tt)

          }else{

          client.connect("localhost",port);

          snd(tt);

          }

          }