Sockets with ActionScript 3.0!!!

Sockets used ones and known are of the most powerful tools of programming for Internet and little used. He is possivel that software talks between itself being in different machines. For example serving Web as the apache is in a machine while the server of data base is in another one. The exchange of information between the machines are made through a communication protocol, in the case of the Internet, the TCP/IP. The Apache machine, twirling, for example the PHP, can be connected in the BD and carry through consults or modify data. The exchange of information in the net is organized by the TCP/IP, but, before the data being changed, it is necessary to create the communication channel between the machines. This is possivel using Sockets. Practically all the programming languages of the present time have support and use sockets. In summary, one programs can receive and transmit messages in TCP/IP opening one socket, and later writing and reading given through socket open. Sockets allows that the communication between processes is independent of its physical localization and the particular characteristics of the used media, that is, does not depend on software, but yes of the used protocol (normally protocols TCP/IP). In summary, socket is a species of “programming function�? that allows to open connections to other computers of the net so that given messages or data are changed between the machines by means of a communication protocol.
ActionScript 3,0 brought amongst the new class, the class flash.net.Socket, that is, now the Flash can be connected to other devices saw sockets.

Let us see an example of the use of sockets with Action Script 3,0, this codigo only connects to the server in door 80:

ActionScript

  1. package {
  2.         import flash.display.Sprite;
  3.     import flash.events.*;
  4.     import flash.net.Socket;
  5.     import flash.util.trace;
  6.    
  7.     public class test_sockets extends Sprite{
  8.         public var host:String = 'http://127.0.0.1';
  9.         public var port:uint = 80;
  10.        
  11.         public function test_sockets(){
  12.             super(host,port);
  13.             var conn:Socket = new Socket();
  14.             conn.connect(host,port);
  15.             conn.addEventListener(EventType.CONNECT,connectListener);
  16.         }
  17.         public function connectListener(event:Event) {
  18.                     trace(event.type); // output: connect
  19.         }
  20.     }
  21. }

Macromedia Flex 2.0 MXML and ActionScript Language Reference
http://livedocs.macromedia.com/labs/1/flex/langref/index.html

Um VNC em FLEX
http://www.ifbin.com/news/2005/11/flex-2-flashvnc-alpha-1-by-darron.html

ActionScript 3.0, Flash, Flash Platform, Flex, Principal, RIA

1 comment


  1. xmas

    Hi
    the socket class looks very cool. But how should I solve the ‘error 2031 : socket error’ ??

Leave a Reply