var socket:Socket; //create the new socket and connect to 127.0.0.1 on port 8080 privatefunction init():void { socket = new Socket(); socket.addEventListener(ProgressEvent.SOCKET_DATA, readSocketData); socket.connect("127.0.0.1", 8080); } // send data to the socket privatefunction sendSocketData(string:String):void { // send the string data and specify the encoding for the string // in this case iso-08859-1, standard western european encoding socket.writeMultiByte(string, "iso-8859-1"); } // when data is passed to socket, read it into a new ByteArray privatefunction readSocketData(progressEvent:ProgressEvent):void { trace(progressEvent.bytesLoaded); var ba:ByteArray = new ByteArray(); trace(socket.readBytes(bs)); }