Hey all!

Thanks for everyone's help recently in helping me iron out a few issues :)

I'm running into another that I'm not sure I fully understand. Due to the
asynchronous nature of action script execution, I'm aware of the need to use
events to simulate a sequence of RPC calls (or, in my case, raw socket
communication).

======================================================
Here's an outline of what's happening:

// Initialize socket object
private var socket : flash.net.Socket;
private var count : int;

private function init() : void {
  count = 0;
  socket = new flash.net.Socket();
  socket.addEventListener( Event.CONNECT, connectHandler );
  socket.addEventListener( Event.CLOSE, closeHandler );
  socket.addEventListener( ProgressEvent.SOCKET_DATA, dataHandler );
  socket.connect( host, port );
}

// Actual implementation initiates an HTTP request to the server for a file
private function connectHandler() : void { ; }

private function closeHandler() : void {
  if( count == 0 ) {
     // Intention: do another round of what we just did
     socket.connect( host, port );
     count == 1;
  }
}

// Actual implementaion outputs data received from socket
private function dataHandler() : void { ; }

===============================================

Essentially, the above code initiates an HTTP connection to the host server
using raw sockets, and requests a document. Once the document is
transmitted, and the socket is closed (socket.connected == false), the
socket object dispatches a close event in which I ask the socket to initiate
a second connection.

The problem is, this second connection never occurs. Not only does the
connect event never fire, a packet sniffing tool on my computer doesn't even
show an attempt at opening a socket. (I also have events registered for
security errors or io errors, and am receiving nothing).

My theory is that, for some reason, I cannot reuse a socket object in code
being executed by a dispatched socket event.

I have no idea if this is true (any help here?), but if it is -- how can I
get around it? Is there a way to do a delayed event dispatch, so that the
socket "finishes" closing (i.e. whatever code was after its own
dispatchEvent call), after which I can start over?

Any input greatly appreciated!

--
Jesse Hallam
University of Waterloo Junior

"For scarcely for a righteous man will one die: yet peradventure for a good
man some would even dare to die. But God commendeth his love toward us, in
that, *while we were yet sinners*, Christ died for us. " (Romans 5:7, 8)

Reply via email to