{"id":18290717,"url":"https://github.com/nikouu/mgba-lua-socket","last_synced_at":"2025-04-09T07:33:57.365Z","repository":{"id":198625416,"uuid":"700619297","full_name":"nikouu/mGBA-lua-Socket","owner":"nikouu","description":"Small project to understand how the mGBA implementation of lua sockets works.","archived":false,"fork":false,"pushed_at":"2023-10-06T04:41:21.000Z","size":138,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T08:08:51.640Z","etag":null,"topics":["csharp","dotnet","lua","lua-script","mgba","socket"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikouu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-10-05T00:27:41.000Z","updated_at":"2024-01-18T16:21:58.000Z","dependencies_parsed_at":null,"dependency_job_id":"4f441eb4-00bd-4600-98b9-39853854ea02","html_url":"https://github.com/nikouu/mGBA-lua-Socket","commit_stats":null,"previous_names":["nikouu/mgba-lua-socket"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikouu%2FmGBA-lua-Socket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikouu%2FmGBA-lua-Socket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikouu%2FmGBA-lua-Socket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikouu%2FmGBA-lua-Socket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikouu","download_url":"https://codeload.github.com/nikouu/mGBA-lua-Socket/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247997863,"owners_count":21030694,"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":["csharp","dotnet","lua","lua-script","mgba","socket"],"created_at":"2024-11-05T14:11:57.632Z","updated_at":"2025-04-09T07:33:57.341Z","avatar_url":"https://github.com/nikouu.png","language":"Lua","readme":"# mGBA lua Socket\nSmall project to understand how the mGBA implementation of lua sockets works and how to connect to it. This is pretty much entirely based off the work [mGBA scripts source code folder](https://github.com/mgba-emu/mgba/tree/master/res/scripts).\n\nThe end goal is to send a message to mGBA via sockets.\n\n## How to run\n0. See my [mGBA-lua-HelloWorld repository](https://github.com/nikouu/mGBA-lua-HelloWorld) for basic setup instructions.\n1. Ensure you're running a ROM in mGBA.\n2. Load `socketserver.lua`\n3. Open `SocketClient.sln` for the manual C# socket client.\n4. Run/debug `SocketClient` \n![](images/MessageReceivedDotnet.jpg)\n\n## Protocol issues?\n- While I'm not awfully familiar with low level sockets and TCP, it seems the code from the mGBA repo doesn't respond with an ACK automatically on a recieve and as such trips up applications sending requests - such as Postman, which stays in an endless connecting state.\n- I've added an ACK manually\n- I've added logging points \n\nSee below for comparisons between the .NET client in the repo and Postman. \n\n| Client            | Result                                          |\n| ----------------- | ----------------------------------------------- |\n| Custom .NET       | ![](images/MessageReceivedDotnet.jpg)           |\n| Postman HTTP      | ![](images/MessageReceivedPostmanHttp.jpg)      |\n| Postman Websocket | ![](images/MessageReceivedPostmanWebsocket.jpg) |\n\nIt seems the [socket error](https://mgba.io/docs/scripting.html#constant-SOCKERR) that comes up is the AGAIN one. However, I'm unsure what this means, and reading the mGBA C source doesn't help me understand either. Just don't know enough low level TCP 🤷‍♀️ (*yet*).\n\n## Notes\n\n- Even after manually adding in a response via `sock:send(\"\u003c|ACK|\u003e\")` seems to also not work and gives a `Error: Parse Error: Expected HTTP/` error:\n\n![](images/PostmanError.jpg)\n\n- I assume there would be a way to make the code protocol compliant such that Postman and other clients can easily connect. However, for the time being, I'm just happy with the C# code working.\n- `SocketTest.lua` is leftover from the copy over from mGBA. It's not used here, but it was used for inspiration to help understand.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikouu%2Fmgba-lua-socket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikouu%2Fmgba-lua-socket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikouu%2Fmgba-lua-socket/lists"}