Note that there are some explanatory texts on larger screens.

plurals
  1. POFlash Socket silently failing to connect
    text
    copied!<p>This is a follow up to a <a href="https://stackoverflow.com/questions/9047398/sockets-in-as3-progressevent-socket-data-event-not-firing">previous</a> question which was a little all over the place.</p> <p>I've dug a little deeper and it seems that my Flash client is failing to establish a connection (after calling <code>connect()</code>, <code>connected</code> is still set to false) but isn't triggering any of the relevant error events or any exceptions as far as I can see...</p> <p>The strange thing is that I'm still able to send data <em>to</em> the server, just not receive data <em>from</em> it. Also, the server itself (written in C) seems to be perfectly happy that there is a connection... very strange. Lastly, while I can send data to the server, it does seem to have a little bit of gibberish at the end of it. Not sure if that's relevant, but it may well be a clue to someone who knows this stuff better than I :)</p> <p>Anyway, this is the most relevant file... ChessSocket.as:</p> <pre><code>import flash.events.*; import flash.errors.*; import flash.net.Socket; public class ChessSocket extends Socket { private var response:String; public function ChessSocket(host:String = null, port:uint = 0) { super(); trace("ChessSocket initialising"); configureListeners(); if (host &amp;&amp; port){ trace("Attempting to connect to "+host+" port:"+port+"..."); try { super.connect(host, port); } catch(e:Error) { trace(e); } if (connected) trace("...connected!"); else trace("...not connected."); } writeln("data please!"); sendRequest(); } private function configureListeners():void { trace("configureListeners"); addEventListener(Event.CLOSE, closeHandler); addEventListener(Event.CONNECT, connectHandler); addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); trace("...listeners added!"); } private function writeln(str:String):void { str += "\n"; try { writeUTFBytes(str); } catch(e:IOError) { trace(e); } } private function sendRequest():void { trace("sendRequest"); response = ""; writeln("GET /"); flush(); } private function readResponse():void { var str:String = readUTFBytes(bytesAvailable); trace("readResponse: " + str); response += str; } private function closeHandler(event:Event):void { trace("closeHandler: " + event); trace(response.toString()); } private function connectHandler(event:Event):void { trace("connectHandler: " + event); sendRequest(); } private function ioErrorHandler(event:IOErrorEvent):void { trace("ioErrorHandler: " + event); } private function securityErrorHandler(event:SecurityErrorEvent):void { trace("securityErrorHandler: " + event); } private function socketDataHandler(event:ProgressEvent):void { trace("socketDataHandler: " + event); readResponse(); } } </code></pre> <p>And this is the kind of trace output I get when I run it:</p> <pre><code>ChessSocket initialising configureListeners ...listeners added! Connecting to 192.168.1.4 port:27015 ...not connected. sendRequest </code></pre> <p>While my C server (running on another machine) outputs the following:</p> <pre><code>Ready to accept a connection... </code></pre> <p>And when I launch the swf:</p> <pre><code>I think we have a connection... Waiting for message... Bytes received: 25 Data received: data please! GET / GET / °»â(░ ¸☺ About to send data... Bytes sent: 25 Waiting for message... </code></pre> <p>Then when I close the swf:</p> <pre><code>About to send data... Bytes sent: 25 exiting... </code></pre> <p>Lastly, the swf is running on an OSX laptop, and I've looked into whether there might be firewall issues getting in the way, but haven't found anything yet. The strangest thing is that it just doesn't seem to do anything when I call <code>connect()</code>...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload