{"id":13528918,"url":"https://github.com/Dvergar/Anette","last_synced_at":"2025-04-01T14:33:36.171Z","repository":{"id":15054049,"uuid":"17780190","full_name":"Dvergar/Anette","owner":"Dvergar","description":"Simple haxe network library","archived":false,"fork":false,"pushed_at":"2019-11-18T16:14:35.000Z","size":52,"stargazers_count":37,"open_issues_count":3,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-24T15:19:31.106Z","etag":null,"topics":["gamedev","networking","protocol","tcp"],"latest_commit_sha":null,"homepage":"","language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"wtfpl","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dvergar.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-15T16:47:32.000Z","updated_at":"2024-10-23T15:25:15.000Z","dependencies_parsed_at":"2022-09-07T23:40:29.307Z","dependency_job_id":null,"html_url":"https://github.com/Dvergar/Anette","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dvergar%2FAnette","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dvergar%2FAnette/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dvergar%2FAnette/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dvergar%2FAnette/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dvergar","download_url":"https://codeload.github.com/Dvergar/Anette/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246655447,"owners_count":20812636,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gamedev","networking","protocol","tcp"],"created_at":"2024-08-01T07:00:28.381Z","updated_at":"2025-04-01T14:33:32.111Z","avatar_url":"https://github.com/Dvergar.png","language":"Haxe","funding_links":[],"categories":["Networking"],"sub_categories":[],"readme":"Anette\n======\n\n*(Node websocket target is broken at the moment)*\n\n*Anette is a haxe network library with a simple API :)*\n\n* Supports C++, Neko, Flash and Javascript client-side.\n* Supports C++, Neko and Javascript (Node) server-side.\n\n**RoadMap**\n\n* Move Node backend frome *nodejs* to *HaxeFoundation/hxnodejs*.\n* UDP sockets.\n\n**Note:** *Client js target will only be served by Node backend for now.*  \n**Note2:** *Node backend depends on [nodejs library](https://github.com/dionjwa/nodejs-std), but since it's overriding some of the haxe library classes it only works if you remove or rename the `haxe` folder in `HaxeToolkit\\haxe\\lib\\nodejs\\x,x,x\\` hoping that it doesn't break your application.*  \n**Note3:** *C++ target seems to have strange disconnection behaviour atm.*\n\n# Server\n\n`new Server(ip:String, port:Int)`\n\nCreates a TCP server object \u0026 bind it to the given host/port.\n\n`server.pump()`\n\nLooks for new messages and put them in the buffer, generally used in a loop.\n\n`server.flush()`\n\nSends datas from the buffer into the internet tubes, generally used in a loop.\n\n`server.onConnection`\n\nCallback function of type `Connection-\u003eVoid` when a connection is established.\n\n`server.onDisconnection`\n\nCallback function of type `Connection-\u003eVoid` when a client disconnects.\n\n`server.onData`\n\nCallback function of type `Connection-\u003eVoid` when data is received. You should then use `connection.input` to read the datas, input inherits from [`haxe.io.BytesInput`](http://api.haxe.org/haxe/io/BytesInput.html).\n\nexample : `server.onData = function(connection:Connection) { connection.input.readString(11) };`\n\n`server.protocol`\n\nProperty of type `Protocol`.\n\nThere is two built-in protocols: `Prefixed` and `Line`\n\nProtocol used to pack \u0026 unpack datas. Note that if you're not using any predefined protocol you'll have to build your own with or without the anette API, otherwise data communication won't be reliable.\n\n* `Prefixed`: Each message is prepended with the length of the message via a short (16bits).\n* `Line`: Each message is separated by CR and/or LF bytes.\n\nexample: `server.protocol = new Prefixed();`\n\n`server.timeout`\n\nProperty of type `Float`, defines the time of inactivity in seconds before the connection is dropped.\n\n\n## Client\n\n`new Client()`\n\nCreates a TCP client object.\n\n`client.pump()`\n\nLooks for new messages and put them in the buffer, generally used in a loop.\n\n`client.flush()`\n\nSends datas from the buffer into the internet tubes, generally used in a loop.\n\n`client.disconnect()`\n\nDrops the connection.\n\n`client.connected`\n\nProperty of type `Bool`, returns the state of the connection.\n\n`client.onConnection`\n\nCallback function of type `Connection-\u003eVoid` when a connection is established.\n\n`client.onDisconnection`\n\nCallback function of type `Connection-\u003eVoid` when a client disconnects.\n\n`client.onData`\n\nCallback function of type `Connection-\u003eVoid` when data is received. You should then use `connection.input` to read the datas, input inherits from [`haxe.io.BytesInput`](http://api.haxe.org/haxe/io/BytesInput.html).\n\nexample : `client.onData = function(connection:Connection) { connection.input.readString(11) };`\n\n`client.protocol`\n\nProperty of type `Protocol`.\n\nThere is two built-in protocols: `Prefixed` and `Line`\n\nProtocol used to pack \u0026 unpack datas. Note that if you're not using any predefined protocol you'll have to build your own with or without the anette API, otherwise data communication won't be reliable.\n\n* `Prefixed`: Each message is prepended with the length of the message via a short (16bits).\n* `Line`: Each message is separated by CR and/or LF bytes.\n\nexample: `client.protocol = new Prefixed();`\n\n`client.timeout`\n\nProperty of type `Float`, defines the time of inactivity in seconds before the connection is dropped.\n\n\n##Connection\n\n`connection.output`\n\nObject which inherits from [`haxe.io.BytesOutput`](http://api.haxe.org/haxe/io/BytesOutput.html). This is what you should use to send datas.\n\nexample : `connection.output.writeString(\"hello world\");`\n\n`connection.input`\n\nObject which inherits from [`haxe.io.BytesInput`](http://api.haxe.org/haxe/io/BytesInput.html). This is what you should use to read datas.\n\nexample : `connection.output.readString(11);`\n\n\n##Server Example\n\n```Haxe\nclass TestServer\n{\n    var server:anette.Server;\n\n    public function new()\n    {\n        this.server = new anette.Server(\"127.0.0.1\", 32000);\n        this.server.onData = onData;\n        this.server.onConnection = onConnection;\n        this.server.onDisconnection = onDisconnection;\n        this.server.protocol = new anette.Protocol.Prefixed();\n        this.server.timeout = 10;\n\n        // DIFFERENT TARGETS, DIFFERENT LOOPS\n        #if js\n        var timer = new haxe.Timer(Std.int(1000 / 60));\n        timer.run = loop;\n        #else\n        while(true) {loop(); Sys.sleep(1/60);}\n        #end\n    }\n\n    function loop()\n    {\n        server.pump();\n        server.flush();\n    }\n\n    function onData(connection:anette.Connection)\n    {\n        trace(\"onData \" + connection.input.readInt16());\n\n        var msgLength = connection.input.readInt8();\n        var msg = connection.input.readString(msgLength);\n        trace(\"onData \" + msg);\n    }\n\n    function onConnection(connection:anette.Connection)\n    {\n        trace(\"CONNNECTION\");\n\n        connection.output.writeInt16(42);\n\n        var msg = \"Hello Client\";\n        connection.output.writeInt8(msg.length);\n        connection.output.writeString(msg);\n    }\n\n    function onDisconnection(connection:anette.Connection)\n    {\n        trace(\"DISCONNECTION\");\n    }\n\n    static function main()\n    {\n        new TestServer();\n    }\n}\n```\n\n\n##Client Example\n\n```Haxe\nclass TestClient\n{\n    var client:anette.Client;\n\n    public function new()\n    {\n        this.client = new anette.Client();\n        this.client.onData = onData;\n        this.client.onConnection = onConnection;\n        this.client.onDisconnection = onDisconnection;\n        this.client.protocol = new anette.Protocol.Prefixed();\n        this.client.timeout = 5;\n        this.client.connect(\"127.0.0.1\", 32000);\n\n        #if flash\n        flash.Lib.current.stage.addEventListener(flash.events.Event.ENTER_FRAME,\n                                                 loop);\n        #elseif (cpp||neko)\n        while(true) {loop(); Sys.sleep(1 / 60);}\n        #elseif js\n        var timer = new haxe.Timer(Std.int(1000 / 60));\n        timer.run = loop;\n        #end\n    }\n\n    #if flash\n    function loop(event:flash.events.Event)\n    #else\n    function loop()\n    #end\n    {\n        if(client.connected)\n        {\n            client.pump();\n            client.flush();\n        }\n    }\n\n    function onData(connection:anette.Connection)\n    {\n        trace(\"onData \" + connection.input.readInt16());\n\n        var msgLength = connection.input.readInt8();\n        var msg = connection.input.readString(msgLength);\n        trace(\"onData \" + msg);\n    }\n\n    function onConnection(connection:anette.Connection)\n    {\n        trace(\"CONNNECTION\");\n        \n        client.connection.output.writeInt16(42);\n\n        var msg = \"Hello Server\";\n        client.connection.output.writeInt8(msg.length);\n        client.connection.output.writeString(msg);\n    }\n\n    function onDisconnection(connection:anette.Connection)\n    {\n        trace(\"DISCONNECTION\");\n    }\n\n    static function main()\n    {\n        new TestClient();\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDvergar%2FAnette","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDvergar%2FAnette","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDvergar%2FAnette/lists"}