[server] host from args
This commit is contained in:
@@ -31,9 +31,9 @@ class Init {
|
||||
private static function getHost():String {
|
||||
#if flash
|
||||
var url = Lib.current.loaderInfo.url;
|
||||
var r:EReg = ~/((app|https?):\/\/?[-_\w\d\.]+(:\d+)?)\/?/;
|
||||
if (r.match(url) && !(r.matched(2) == "app")) {
|
||||
return r.matched(1);
|
||||
var r:EReg = ~/(app|https?):\/\/?([-_\w\d\.]+)(:\d+)?\/?/;
|
||||
if (r.match(url) && !(r.matched(1) == "app")) {
|
||||
return r.matched(2);
|
||||
} else {
|
||||
return "localhost";
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import sys.net.Socket;
|
||||
|
||||
class Server extends ThreadServer<Session, Bytes> {
|
||||
|
||||
private static inline var TAG = "Server";
|
||||
private static inline var TAG = 'Server';
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
@@ -26,16 +26,17 @@ class Server extends ThreadServer<Session, Bytes> {
|
||||
|
||||
override public function clientConnected(s:Socket):Session {
|
||||
var session = new Session(s);
|
||||
L.d(TAG, "Client connected");
|
||||
L.d(TAG, 'Client connected');
|
||||
return session;
|
||||
}
|
||||
|
||||
override public function clientDisconnected(session:Session) {
|
||||
L.d(TAG, "Client disconnected");
|
||||
L.d(TAG, 'Client disconnected');
|
||||
session.connection.handler.emit(ConnectionEvent.DISCONNECTED);
|
||||
}
|
||||
|
||||
override public function readClientMessage(session:Session, buf:Bytes, pos:Int, len:Int) {
|
||||
//L.d(TAG, 'Client message: ${buf}');
|
||||
return {msg: buf.sub(pos, len), bytes: len};
|
||||
}
|
||||
|
||||
@@ -52,12 +53,15 @@ class Server extends ThreadServer<Session, Bytes> {
|
||||
#if debug
|
||||
L.push(new SocketLogger());
|
||||
#end
|
||||
L.d(TAG, "Running");
|
||||
L.i(TAG, "Build: " + CompilationOption.get("build"));
|
||||
L.d(TAG, 'Running');
|
||||
L.i(TAG, 'Build: ${CompilationOption.get("build")}');
|
||||
Provider.setFactory(IConfigBundle, ServerConfigBundle);
|
||||
Provider.setFactory(ILevelBundle, ServerLevelBundle);
|
||||
Provider.setFactory(IControlFactory, NoneControlFactory);
|
||||
var host:String = Sys.args().length > 0 ? Sys.args()[0] : "localhost";
|
||||
var port:Int = Sys.args().length > 1 ? Std.parseInt(Sys.args()[1]) : 5000;
|
||||
var wserver = new Server();
|
||||
wserver.run("localhost", 5000);
|
||||
L.i(TAG, 'Start on ${host}:${port}');
|
||||
wserver.run(host, port);
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,16 @@ import sys.net.Socket;
|
||||
typedef ServerConnection = IConnection<Response, Request>;
|
||||
|
||||
class Session {
|
||||
private static inline var TAG = 'Session';
|
||||
|
||||
private static var POLICY_FILE:String = [
|
||||
'<?xml version="1.0"?>',
|
||||
'<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">',
|
||||
'<cross-domain-policy>',
|
||||
'<site-control permitted-cross-domain-policies="master-only"/>',
|
||||
'<allow-access-from domain="*" to-ports="*"/>',
|
||||
'</cross-domain-policy>'
|
||||
].join('\n');
|
||||
|
||||
public static var sessions:Map<String, Session> = new Map<String, Session>();
|
||||
|
||||
@@ -53,6 +63,12 @@ class Session {
|
||||
connection.pushData(bytes);
|
||||
} else {
|
||||
var str:String = bytes.getString(0, bytes.length);
|
||||
if (str == '<policy-file-request/>' + String.fromCharCode(0)) {
|
||||
L.d(TAG, 'policy-file-request');
|
||||
socket.output.writeString(POLICY_FILE + String.fromCharCode(0));
|
||||
socket.output.flush();
|
||||
return;
|
||||
}
|
||||
if (StringTools.startsWith(str, "GET")) {
|
||||
connection = new NekoWebConnection<Response, Request>(socket, Request);
|
||||
} else {
|
||||
@@ -65,7 +81,7 @@ class Session {
|
||||
}
|
||||
|
||||
private function onConnectionEvent(event:ConnectionEvent):Void {
|
||||
L.d('Session', '${event}');
|
||||
L.d(TAG, '${event}');
|
||||
}
|
||||
|
||||
public function onRequest(request:Request):Void {
|
||||
|
||||
Reference in New Issue
Block a user