[haXe] Help needed with ServerLoop
Michelangelo Capraro
michelangelo at tinlion.com
Fri Nov 3 10:28:00 CET 2006
hey there all,
I'm trying to write a simple socket server with the new neko.net.ServerLoop in haxe 1.08. I have one working in the old haxe and have re-done it in PHP using pear. now I want to try it in haxe again, but am having trouble. in php pear (using net_server) I don't really need to know much about bytes and buffers. Ijust get a callback with that data from the client (already buffered to the end of the message) and I can deal with things easily from there. I would like to create a class that abstracts the server loop in much the same way. I have a test right now that works but crashes on larger amounts of data (about 6500 bytes worth). here is my test, does this look right at all? also, I don't see anywhere that neko.net.ServerLoop is forking its own thread, do I need to do that myself?
public static function main()
{
host = new neko.net.Host("192.168.1.100");
server = new neko.net.ServerLoop(newData);
server.processClientData = processClientData;
server.run(host, 8080);
}
/**
* gets called when a client posts data, must return it to the server
* @param clientSocket The socket of the client posting the data
*/
public static function newData(clientSocket:neko.net.Socket):Dynamic
{
var clientoBj:ClientObject = { id:clientCount, name:"foo" };
clientCount++;
return clientoBj;
}
public static function processClientData( d : ClientObject, buf : String, bufpos : Int, buflen : Int ):Dynamic
{
var data:String = "";
var commandEnd:Int = buf.indexOf(Std.chr(0));
if (commandEnd != -1) {
data = buf.substr(0, commandEnd);
}
if (data != "") trace("processClientData: \n\n" + data + "\n\n");
var returnLen:Int = data.length;
if (returnLen > 0) returnLen++;
return returnLen;
}
== Tin Lion Creative ==
Michelangelo Capraro
tinlion.com
skip-intro.org hopbot.com number-9.com
More information about the Haxe
mailing list