Hey dude I have played quite a bit with sockets now. I was packet
sniffing what flash sent out and the diference between writeUTF and
writeUTFBytes is the first two binary values of the writeUTF. Flex
documentation says that its the pointer to the binary stream length. I
dont think this format (the length pointer) is used in the http protcol.
The reason I think MM added it was a way to stop blocking through the
data when reading it. Note that you have to use something like
"availableBytes" protpery to read the data......as3 doesnt seem to be
able to block through it (read it as it comes in). So my guessing is
that this method might come into play more with the proprietry MM
systems later.
As always I could be way off so if you know better please let me know.
Just what I have got so far.
Cheers
Campbell
> Hello!
>
> I have been playing with the new Socket class for binary sockets. The
> current code ain't talking to
> binary yet. It's just doing a simple HTTP Request which /seems/ work.
> Please don't look at the code or
> implementation that's really smelly.
>
> Anyone already able to use buttons or textareas in a AS3 only project?
>
> Yours,
> Weyert de Boer
>
> package {
>
> // oh oh, its good to have a sockets demo in the Delphi 2005 demos
> directory!
>
> import flash.display.MovieClip;
> import flash.util.trace;
> import flash.net.*;
> import flash.geom.*;
> import flash.net.URLRequest;
> import flash.events.*;
> import flash.util.ByteArray;
> import flash.util.SetIntervalTimer;
> import flash.display.Sprite;
> import mx.controls.Button;
> import mx.utils.Delegate;
>
> /**
> * Derives of the Socket class
> *
> * @see flash.net
> */
> public class SimpleSocket extends Socket { }
>
> public class BinarySocketsView {
>
> private var btnGo: Button;
>
> public function BinarySocketsView( target:MovieClip ) {
> btnGo = new Button();
> btnGo.label = "GO!";
> target.addChild( btnGo );
> }
>
> public function updateMemoField( text: String ) {
> trace( "TEXT: \n\r " + text );
> }
> }
>
> /**
> * BinarySocket example
> * The first socket example will try to access a HTTP server
> * use the Socket-class. I am hoping such requests aren't getting
> * redirect to something magic functions. Oh well, we will see.
> *
> * NOTE: Don't forget to alter the two constants !
> */
> public class BinarySocketExample extends MovieClip {
>
> private var socket:SimpleSocket;
> private var connected:Boolean;
> private var view: BinarySocketsView;
>
> /**
> * Constants
> */
> private const serverName: String = "www.google.nl";
> private const serverPort: Number = 80;
> private var request: String = "";
>
> /**
> *
> */
> public function BinarySocketExample() {
> this.connected = false;
>
> //
> // GUI STUFF
> this.view = new BinarySocketsView( this );
> this.view.updateMemoField( "" );
>
> //
> //
> socket = new SimpleSocket();
> socket.connect( this.serverName, this.serverPort );
>
> socket.addEventListener( EventType.CONNECT, connectListener );
> //socket.addEventListener( ErrorEvent.IO_ERROR,
> securityErrorListener );
> socket.addEventListener( EventType.CLOSE, stuff );
> socket.addEventListener( ProgressEventType.PROGRESS,
> progressListener );
> socket.addEventListener( EventType.COMPLETE,
completeListener );
> socket.addEventListener( ProgressEventType.SOCKET_DATA,
> socketDataListener);
> }
>
> public function stuff( event:Event) {
> trace( "REQUEST RESULT:\r\n\r\n" );
> trace( this.request );
> }
>
> public function completeListener( event:Event ) {
> trace( "COMPLETE: " + event.toString() );
> }
>
> public function socketDataListener( event:ProgressEvent ) {
> var incomingData: String;
>
> if ( event.bytesLoaded >= 0 ) {
> // trace( "SOCKET DATA: " + event.toString() );
> incomingData = this.socket.readUTFBytes(
> event.bytesLoaded );
> this.request += incomingData;
> }
> }
>
> public function securityErrorListener( event:IOErrorEvent ) {
> trace( "ERROR: " + event.type );
> }
>
>
>
> public function progressListener( event:ProgressEvent ) {
> trace( "PROGRESS " + event.toString() );
> }
>
> /**
> * Stuff....
> */
> public function connectListener( event:Event ) {
> var httpRequest:String;
> trace( "Attempting to connect to '" + this.serverName + "'
> on port '" + this.serverPort.toString() + "'..." );
>
> httpRequest = "GET / HTTP/1.0\r\n";
> httpRequest += "User-Agent: Mozilla 4.0 (X; I;
> Linux-2.0.35i586)\r\n";
> httpRequest += "Host: " + this.serverName + "\r\n";
> httpRequest += "Accept: */*\r\n";
> httpRequest += "\r\n\r\n";
>
> //trace( httpRequest );
> //trace( "----------------------------" );
>
> //
> if ( socket.connected ) {
> trace( "SOCKET CONNECTED." );
> socket.writeUTFBytes( httpRequest );
> // TODO wdb Check why writeUTF is not working, probably
> some good reason for which missing at 5 o'clock in the mornig.
> trace( "OK? " );
> }
> }
>
> }
> }
> _______________________________________________
> Flashcoders mailing list
> [email protected]
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
>
--
_______________________________________________
Flashcoders mailing list
[email protected]
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders