{"id":25019143,"url":"https://github.com/parinpan/protoevent","last_synced_at":"2025-04-13T03:42:09.735Z","repository":{"id":57549347,"uuid":"261718023","full_name":"parinpan/protoevent","owner":"parinpan","description":"ProtoEvent is an event-based TCP connection handling library for Go.","archived":false,"fork":false,"pushed_at":"2020-05-13T11:19:09.000Z","size":65,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T20:51:30.142Z","etag":null,"topics":["client","event-handlers","golang","server","tcp","udp"],"latest_commit_sha":null,"homepage":"","language":"Go","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/parinpan.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}},"created_at":"2020-05-06T09:53:44.000Z","updated_at":"2024-04-17T07:58:13.000Z","dependencies_parsed_at":"2022-08-27T01:31:24.320Z","dependency_job_id":null,"html_url":"https://github.com/parinpan/protoevent","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parinpan%2Fprotoevent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parinpan%2Fprotoevent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parinpan%2Fprotoevent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parinpan%2Fprotoevent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parinpan","download_url":"https://codeload.github.com/parinpan/protoevent/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248661028,"owners_count":21141384,"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":["client","event-handlers","golang","server","tcp","udp"],"created_at":"2025-02-05T11:38:57.060Z","updated_at":"2025-04-13T03:42:09.714Z","avatar_url":"https://github.com/parinpan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e \n\t\u003cimg src=\"https://user-images.githubusercontent.com/14908455/81298347-dcb05e80-909e-11ea-8aa3-44ecf2c46af9.png\"/\u003e\n\u003c/p\u003e\n\nProtoEvent is an event-based TCP connection handling library in Golang. It's simple and not exploiting too much the basic functionality of making a new protocol connection. ProtoEvent reimplements `net.Listener` and `net.Conn`  interface to have extended ability of capturing various events that happened in network communication.\n\n# Background\nIt's painful enough when you have to look after your simple network application codebase which is not well-organized ends up with producing more spaghetti code. At least, we're now able to organize application logics based on a certain network event.\n\n# Installation\n```\ngo get -u https://github.com/parinpan/protoevent\n```\n\n# Demo\n![ezgif com-video-to-gif](https://user-images.githubusercontent.com/14908455/81297569-a0303300-909d-11ea-90f4-935d1d16925b.gif)\n\n# Examples\nServer side application:\n```golang\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"net\"\n\n\t\"github.com/parinpan/protoevent\"\n)\n\ntype Message struct {\n\tFrom string `json:\"from\"`\n}\n\nfunc main() {\n\tservant, event, err := protoevent.CreateServant(\"tcp\", \"0.0.0.0:8089\")\n\n\tif nil != err {\n\t\tpanic(err)\n\t}\n\n\tevent.OnConnectionError(func(err error) {\n\t\n\t})\n\n\tevent.OnConnectionAccepted(func(conn net.Conn) {\n\t\tfmt.Println(\"Accepting new connection: \", conn.RemoteAddr())\n\t})\n\n\tevent.OnConnectionClosed(func(conn net.Conn) {\n\t\n\t})\n\n\tevent.OnReceiveMessageError(func(conn net.Conn, err error) {\n\t\n\t})\n\n\tevent.OnMessageReceived(func(conn net.Conn, message []byte, rawMessage []byte) {\n\t\tfmt.Println(\"Received a message: \", string(message))\n\t\t\n\t\tvar msg Message\n\t\t_ = json.Unmarshal(message, \u0026msg)\n\t\t\n\t\t// send a message back to client\n\t\tsayHiMessage := fmt.Sprint(\"Hi \", msg.From, \". Welcome to ProtoEvent!\")\n\t\tconn.Write([]byte(sayHiMessage))\n\t})\n\n\tevent.OnSendMessageError(func(conn net.Conn, message []byte, err error) {\n\t\n\t})\n\n\tevent.OnMessageSent(func(conn net.Conn, message []byte) {\n\t\tfmt.Println(\"Sent a message: \", string(message))\n\t})\n\n\tservant.SetDefaultReadSize(4096) // set default read size per chunk in bytes\n\tservant.Serve()\n}\n```\n\nClient side application:\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"net\"\n\n\t\"github.com/parinpan/protoevent\"\n)\n\nfunc main() {\n\tagent, event := protoevent.CreateAgent(\"tcp\", \"0.0.0.0:8089\")\n\tagent.SetDefaultReadSize(4096) // set default read size per chunk in bytes\n\n\tevent.OnConnectionError(func(err error) {\n\n\t})\n\n\tevent.OnConnectionAccepted(func(conn net.Conn) {\n\t\tfmt.Println(\"Accepting new connection: \", conn.RemoteAddr())\n\t})\n\n\tevent.OnConnectionClosed(func(conn net.Conn) {\n\n\t})\n\n\tevent.OnReceiveMessageError(func(conn net.Conn, err error) {\n\n\t})\n\n\tevent.OnMessageReceived(func(conn net.Conn, message []byte, rawMessage []byte) {\n\t\tfmt.Println(\"Received a message: \", string(message))\n\t})\n\n\tevent.OnSendMessageError(func(conn net.Conn, message []byte, err error) {\n\n\t})\n\n\tevent.OnMessageSent(func(conn net.Conn, message []byte) {\n\t\tfmt.Println(\"Sent a message: \", string(message))\n\t})\n\n\t// trigger a message to get connected with the server at first\n\terr := agent.Run(func(conn net.Conn) error {\n\t\t_, err := conn.Write([]byte(`{\"from\": \"AgentV1\"}`))\n\t\treturn err\n\t})\n\n\tif nil != err {\n\t\tpanic(err)\n\t}\n}\n```\n# Contact Me \nIf you have any inquiries. You can catch me up on:\n- [Linkedin](https://linkedin.com/in/fachrinfan)\n- [Twitter](https://twitter.com/fachrinfan)\n- [Instagram](https://instagram.com/fachrinfan)\n- [Email](mailto:fachrin.nasution@gmail.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparinpan%2Fprotoevent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparinpan%2Fprotoevent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparinpan%2Fprotoevent/lists"}