<commit_before>package;

import neko.Lib;
import sys.net.Socket;
import neko.net.ThreadServer;
import haxe.io.Bytes;

typedef Client = {
	var id : Int;
}

typedef Message = {
	var str : String;
}

class Server extends ThreadServer<Client, Message>
{
	public static function main()
	{
		var server = new Server();
		server.run("localhost", 1234);
	}
	
	// create a Client
	override function clientConnected( s : Socket ) : Client
	{
		var num = Std.random(100);
		Lib.println("client " + num + " is " + s.peer());
		return { id: num };
	}

	override function clientDisconnected( c : Client )
	{
		Lib.println("client " + Std.string(c.id) + " disconnected");
	}

	override function readClientMessage( c : Client, buf : haxe.io.Bytes, pos : Int, len : Int ) : { msg : Message, bytes : Int }
	{
		// find out if there's a full message, and if so, how long it is.
		var complete = false;
		var cpos = pos;
		while (cpos < (pos+len) && !complete)
		{
			//check for a ENTER to signify a complete message
			complete = (buf.get(cpos) == 10 || buf.get(cpos) == 13);
			cpos++;
		}<commit_msg>Add some fancy notification when server started.<commit_after>package;

import neko.Lib;
import sys.net.Socket;
import neko.net.ThreadServer;
import haxe.io.Bytes;

typedef Client = {
	var id : Int;
}

typedef Message = {
	var str : String;
}

class Server extends ThreadServer<Client, Message>
{
	public static function main()
	{
		var server = new Server();
		server.run("localhost", 1234);
	}
	
	override function init() {
		super.init();
		Lib.println("ͻ");
		Lib.println(" SERVER STARTED ");
		Lib.println("ͼ");
	}
	
	// create a Client
	override function clientConnected( s : Socket ) : Client
	{
		var num = Std.random(100);
		Lib.println("client " + num + " is " + s.peer());
		return { id: num };
	}

	override function clientDisconnected( c : Client )
	{
		Lib.println("client " + Std.string(c.id) + " disconnected");
	}

	override function readClientMessage( c : Client, buf : haxe.io.Bytes, pos : Int, len : Int ) : { msg : Message, bytes : Int }
	{
		// find out if there's a full message, and if so, how long it is.
		var complete = false;
		var cpos = pos;
		while (cpos < (pos+len) && !complete)
		{
			//check for a ENTER to signify a complete message
			complete = (buf.get(cpos) == 10 || buf.get(cpos) == 13);
			cpos++;
		}
{'fraction_non_alphanumeric': 0.1439621830683283, 'fraction_numerical': 0.009454232917920068, 'mean_word_length': 3.3271375464684017, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5165170', 'n_tokens_mistral': 879, 'n_tokens_neox': 792, 'n_words': 245}