Copy link to clipboard
Copied
I'm trying to implement a RTSP client in Actionscript 3. During the RTSP negotiations, my Socket instance is never firing the SOCKET_DATA event when the server sends data. I can see the network traffic in Wireshark, but my handler is never called when I use IE or Chrome. Firefox works fine and my handler is called whenever data is received from the server. Also, when I run it on MacOS or 32 bit Microsoft Windows 7, Firefox, Chrome, and IE all work.
The command causing problems is the RTSP OPTIONS command. After sending that command, I never get the SOCKET_DATA event until I send another packet and then I get both responses from the server. Below is some sample code. If you single click the player, the OPTIONS command is sent but the handler is never called. If you double click the player, a DESCRIBE command is sent and the SOCKET_DATA handler is called for the previous OPTIONS command and then DESCRIBE command.
I'm pretty new to Actionscript and wondering if I am missing something or maybe not initializing something correctly.
I can add the python server code if that helps or I can recreate the problem just using netcat to server the port.
Client Code
-----------------
package {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.IOErrorEvent
import flash.events.ProgressEvent;
import flash.events.SecurityErrorEvent;
import flash.external.ExternalInterface;
import flash.net.Socket;
import flash.utils.ByteArray;
public class TestSocket extends Sprite {
private var host:String = "localhost";
private var port:uint = 8554;
private var sock:Socket;
public function TestSocket() {
this.stage.doubleClickEnabled = true;
this.stage.addEventListener(MouseEvent.CLICK, onClicked);
this.stage.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClicked);
this.log("Connecting to " + this.host + " port: " + this.port)
this.sock = new Socket();
this.sock.addEventListener(Event.CONNECT, onConnect);
this.sock.addEventListener(ProgressEvent.SOCKET_DATA, onSocketData);
this.sock.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
this.sock.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
this.sock.connect(this.host, this.port);
}
private function onConnect(event:Event):void {
this.log("onConnected - " + event);
}
private function onSocketData(event:ProgressEvent):void {
var temp:ByteArray = new ByteArray();
this.log("onSocketData bytesAvailable: " + this.sock.bytesAvailable);
this.sock.readBytes(temp);
this.log(temp.toString());
}
private function onIOError(event:IOErrorEvent):void {
this.log("onIOError - " + event.text);
}
private function onSecurityError(event:SecurityErrorEvent):void {
this.log("onSecurityError - " + event.text);
}
private function onClicked(event:MouseEvent):void {
sendOptions();
}
private function onDoubleClicked(event:MouseEvent):void {
sendDescribe();
}
private function sendOptions():void {
writeData("OPTIONS A 1\r\n\r\n");
}
private function sendDescribe():void {
writeData("DESCRIBE A 1\r\n\r\n");
}
private function sendGetParameter():void {
writeData("GET_PARAMETER\r\n\r\n")
}
private function writeData(data:String) {
this.log('Writing Data:' + data);
this.sock.writeUTFBytes(data);
this.sock.flush();
}
private function log(message:String):void {
ExternalInterface.call("console.log", message);
}
}
}
Have something to add?