FLash cs4 output:
Connecting... Error #2044: unhandled NetStatusEvent:。 level=error, code=NetConnection.Connect.Rejected at HelloWorld/connectHandler() Server log: Sat 01:54:17 PM: Core (4072) connection to admin accepted. ----------------connect again---------------------------- Sat 02:09:31 PM: Core (1196) connection to admin accepted. Sat 02:09:31 PM: Core (1196) sending register cmd to edge. Sat 02:09:31 PM: Core (1196) socket migration failed. ----------------connect again---------------------------- Sat 02:12:03 PM: Core (1196) socket migration failed.
Here is the code:
HelloWorld.as
package {
import flash.display.MovieClip;
import flash.net.Responder;
import flash.net.NetConnection;
import flash.events.NetStatusEvent;
import flash.events.MouseEvent;
public class HelloWorld extends MovieClip {
// Represents a network connection.
private var nc:NetConnection;
// Responder for call to server's serverHelloMsg -- see onReply() below.
private var myResponder:Responder = new Responder(onReply);
// Constructor.
public function HelloWorld() {
// Set display values.
textLbl.text = "";
connectBtn.label = "Connect";
// Register a listener for mouse clicks on the button.
connectBtn.addEventListener(MouseEvent.CLICK, connectHandler);
}
// When button is pressed, connect to or disconnect from the server.
public function connectHandler(event:MouseEvent):void {
if (connectBtn.label == "Connect") {
trace("Connecting...");
nc = new NetConnection();
// Connect to the server.
nc.connect("rtmp://localhost/HelloWorld");
// Call the server's client function serverHelloMsg, in HelloWorld.asc.
nc.call("serverHelloMsg", myResponder, "World");
connectBtn.label = "Disconnect";
} else {
trace("Disconnecting...");
// Close the connection.
nc.close();
connectBtn.label = "Connect";
textLbl.text = "";
}
}
// Responder function for nc.call() in connectHandler().
private function onReply(result:Object):void {
trace("onReply received value: " + result);
textLbl.text = String(result);
}
}
}
HelloWorld.asc
// Server-side action taken upon connect request.
application.onConnect = function( client ) {
// Define new client function for a nc.call().
client.serverHelloMsg = function( helloStr ) {
return "Hello, " + helloStr + "!";
}
// Accept the connection.
application.acceptConnection( client );
}