{"id":13528940,"url":"https://github.com/ianharrigan/hxWebSockets","last_synced_at":"2025-04-01T14:33:42.433Z","repository":{"id":45797274,"uuid":"160685972","full_name":"ianharrigan/hxWebSockets","owner":"ianharrigan","description":"hxWebSockets - websockets for all haxe platforms","archived":false,"fork":false,"pushed_at":"2025-01-12T18:46:36.000Z","size":133,"stargazers_count":84,"open_issues_count":13,"forks_count":20,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-03-01T22:32:59.271Z","etag":null,"topics":["haxe","websockets"],"latest_commit_sha":null,"homepage":"https://github.com/ianharrigan/hxWebSockets","language":"Haxe","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ianharrigan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-12-06T14:25:53.000Z","updated_at":"2025-01-12T18:46:40.000Z","dependencies_parsed_at":"2024-11-02T15:31:45.990Z","dependency_job_id":"ed664f8c-8336-43ba-8b43-a62aab71e3f1","html_url":"https://github.com/ianharrigan/hxWebSockets","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/ianharrigan%2FhxWebSockets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianharrigan%2FhxWebSockets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianharrigan%2FhxWebSockets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ianharrigan%2FhxWebSockets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ianharrigan","download_url":"https://codeload.github.com/ianharrigan/hxWebSockets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246655472,"owners_count":20812640,"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":["haxe","websockets"],"created_at":"2024-08-01T07:00:29.129Z","updated_at":"2025-04-01T14:33:37.889Z","avatar_url":"https://github.com/ianharrigan.png","language":"Haxe","funding_links":[],"categories":["Networking"],"sub_categories":[],"readme":"# hxWebSockets\n###### Fork of https://github.com/soywiz/haxe-ws\n\nHaxe Websockets supporting the following targets:\n- C++\n- HashLink\n- JavaScript\n\nIncomplete support for Java and C#.\n\n# Examples\n\n### Client\n\n```haxe\nimport haxe.io.Bytes;\nimport hx.ws.Log;\nimport hx.ws.WebSocket;\nclass Main {\n    static function main() {\n        Log.mask = Log.INFO | Log.DEBUG | Log.DATA;\n        var ws = new WebSocket(\"ws://localhost:5000\");\n        ws.onopen = function() {\n            ws.send(\"alice string\");\n            ws.send(Bytes.ofString(\"alice bytes\"));\n        }\n        #if sys\n        Sys.getChar(true);\n        #end\n    }\n}\n```\n\n### Server\n\n`Main.hx`\n```haxe\nimport hx.ws.Log;\nimport hx.ws.WebSocketServer;\nclass Main {\n    static function main() {\n        Log.mask = Log.INFO | Log.DEBUG | Log.DATA;\n        var server = new WebSocketServer\u003cMyHandler\u003e(\"localhost\", 5000, 10);\n        server.start();\n    }\n}\n```\n\n`MyHandler.hx`\n```haxe\nimport hx.ws.SocketImpl;\nimport hx.ws.WebSocketHandler;\nimport hx.ws.Types;\nclass MyHandler extends WebSocketHandler {\n    public function new(s: SocketImpl) {\n        super(s);\n        onopen = function() {\n            trace(id + \". OPEN\");\n        }\n        onclose = function() {\n            trace(id + \". CLOSE\");\n        }\n        onmessage = function(message: MessageType) {\n            switch (message) {\n                case BytesMessage(content):\n                    trace(content.readAllAvailableBytes());\n                case StrMessage(content):\n                    var str = \"echo: \" + content;\n                    trace(str);\n                    send(str);\n            }\n        }\n        onerror = function(error) {\n            trace(id + \". ERROR: \" + error);\n        }\n    }\n}\n```\n\n### Secure server\n\n`Main.hx`\n```haxe\npackage;\n\nimport hx.ws.WebSocketSecureServer;\n\nimport sys.ssl.Key;\nimport sys.ssl.Certificate;\n\n\nclass Main\n{\n\n    public static function main()\n    {\n        // self signed ceritificate\n        var cert = Certificate.loadFile('example.cert');\n        var key = Key.loadFile('example.key');\n\n        var server = new WebSocketSecureServer\u003cSocketHandler\u003e(\"0.0.0.0\", 5000,\n            cert, // actual certificate\n            key,  // key to the certificate\n            cert, // certificate chain to aid clients finding way to trusted root,\n                  // pass cert in case of selfsigned\n            10);\n        server.start();\n    }\n}\n```\n\nInitialize client with `wss` protocol, e.g. `new WebSocket(\"wss://localhost:5000\");`\n\n### Accepting selfsigned certs\n\nOnly on sys platforms, since they expose SslSocket. If you need to test JS with selfsigned certs, you need to import certificate into your browser trusted collection.\n\n```haxe\nimport hx.ws.Log;\nimport hx.ws.WebSocket;\n\nimport hx.ws.SocketImpl;\nimport hx.ws.SecureSocketImpl;\n\nclass WebSocketNoVerify extends WebSocket {\n    override private function createSocket():SocketImpl\n    {\n        if (_protocol == \"wss\") {\n            var socket:SecureSocketImpl = cast super.createSocket();\n            socket.verifyCert = false;\n            return socket;\n        }\n        return super.createSocket();\n    }\n}\n\nclass Main {\n    static function main() {\n        Log.mask = Log.INFO | Log.DEBUG | Log.DATA;\n        var ws = new WebSocketNoVerify(\"wss://localhost:5000\");\n        ws.onopen = function() {\n            ws.send(\"alice string\");\n        }\n        Sys.getChar(true);\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianharrigan%2FhxWebSockets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fianharrigan%2FhxWebSockets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fianharrigan%2FhxWebSockets/lists"}