[server] add module
|
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
|
Before Width: | Height: | Size: 503 B After Width: | Height: | Size: 503 B |
|
Before Width: | Height: | Size: 499 B After Width: | Height: | Size: 499 B |
|
Before Width: | Height: | Size: 569 B After Width: | Height: | Size: 569 B |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
|
Before Width: | Height: | Size: 741 B After Width: | Height: | Size: 741 B |
|
Before Width: | Height: | Size: 740 B After Width: | Height: | Size: 740 B |
|
Before Width: | Height: | Size: 540 B After Width: | Height: | Size: 540 B |
|
Before Width: | Height: | Size: 564 B After Width: | Height: | Size: 564 B |
|
Before Width: | Height: | Size: 582 B After Width: | Height: | Size: 582 B |
|
Before Width: | Height: | Size: 619 B After Width: | Height: | Size: 619 B |
|
Before Width: | Height: | Size: 681 B After Width: | Height: | Size: 681 B |
|
Before Width: | Height: | Size: 580 B After Width: | Height: | Size: 580 B |
|
Before Width: | Height: | Size: 160 KiB After Width: | Height: | Size: 160 KiB |
|
Before Width: | Height: | Size: 78 KiB After Width: | Height: | Size: 78 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
49
src/server/haxe/ru/m/puzzlez/PuzzlezServer.hx
Normal file
@@ -0,0 +1,49 @@
|
||||
package ru.m.puzzlez;
|
||||
|
||||
import hw.log.TraceLogger;
|
||||
import cpp.net.ThreadServer;
|
||||
import sys.net.Socket;
|
||||
import haxe.io.Bytes;
|
||||
|
||||
typedef Session = Dynamic;
|
||||
typedef Message = Bytes;
|
||||
typedef ClientMessage<M> = {
|
||||
var msg:M;
|
||||
var bytes:Int;
|
||||
}
|
||||
|
||||
class PuzzlezServer extends ThreadServer<Session, Message> {
|
||||
|
||||
private static inline var TAG = 'Server';
|
||||
|
||||
override public function clientConnected(socket:Socket):Session {
|
||||
var session = null; // new Session(socket);
|
||||
L.d(TAG, 'Client connected');
|
||||
return session;
|
||||
}
|
||||
|
||||
override public function clientDisconnected(session:Session) {
|
||||
L.d(TAG, 'Client disconnected');
|
||||
//session.disconnect();
|
||||
}
|
||||
|
||||
override public function readClientMessage(session:Session, buf:Bytes, pos:Int, len:Int): ClientMessage<Message> {
|
||||
//L.d(TAG, 'Client message: ${buf}');
|
||||
return {msg: buf.sub(pos, len), bytes: len};
|
||||
}
|
||||
|
||||
override public function clientMessage(session:Session, message:Message) {
|
||||
//session.pushData(bytes);
|
||||
}
|
||||
|
||||
public static function main():Void {
|
||||
L.push(new TraceLogger());
|
||||
L.d(TAG, 'Running');
|
||||
L.i(TAG, 'Build: ${CompilationOption.get("build")}');
|
||||
var host:String = Sys.args().length > 0 ? Sys.args()[0] : "0.0.0.0";
|
||||
var port:Int = Sys.args().length > 1 ? Std.parseInt(Sys.args()[1]) : 5000;
|
||||
var wserver = new PuzzlezServer();
|
||||
L.i(TAG, 'Start on ${host}:${port}');
|
||||
wserver.run(host, port);
|
||||
}
|
||||
}
|
||||