{"id":20572056,"url":"https://github.com/netease/libpomelo","last_synced_at":"2025-08-21T23:32:37.720Z","repository":{"id":6642255,"uuid":"7886413","full_name":"NetEase/libpomelo","owner":"NetEase","description":"[DEPRECATED] Please Go to https://github.com/NetEase/libpomelo2","archived":false,"fork":false,"pushed_at":"2015-06-26T09:36:35.000Z","size":8746,"stargazers_count":116,"open_issues_count":2,"forks_count":74,"subscribers_count":47,"default_branch":"master","last_synced_at":"2024-04-13T23:44:09.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"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/NetEase.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-01-29T06:02:22.000Z","updated_at":"2023-11-17T02:14:44.000Z","dependencies_parsed_at":"2022-08-26T08:41:14.338Z","dependency_job_id":null,"html_url":"https://github.com/NetEase/libpomelo","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Flibpomelo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Flibpomelo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Flibpomelo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NetEase%2Flibpomelo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NetEase","download_url":"https://codeload.github.com/NetEase/libpomelo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542287,"owners_count":18242332,"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":[],"created_at":"2024-11-16T05:18:11.168Z","updated_at":"2024-12-20T06:05:58.375Z","avatar_url":"https://github.com/NetEase.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# This project is deprecated, please go to [https://github.com/NetEase/libpomelo2](https://github.com/NetEase/libpomelo2)\n\n##libpomelo\n\nlibpomelo is a C language client SDK for Pomelo, supporting the Pomelo\nprotocol definition in Pomelo 0.3 version.\n\n * Homepage: \u003chttp://pomelo.netease.com/\u003e\n * Mailing list: \u003chttps://groups.google.com/group/pomelo\u003e\n * Documentation: \u003chttp://github.com/NetEase/pomelo\u003e\n * Wiki: \u003chttps://github.com/NetEase/pomelo/wiki/\u003e\n * Issues: \u003chttps://github.com/NetEase/pomelo/issues/\u003e\n * Tags: game, nodejs\n\n##Dependencies\n\n* [libuv](https://github.com/joyent/libuv) - Cross platform layer, mainly using Network IO and thread.\n* [jansson](https://github.com/akheron/jansson) - JSON encode and decode library.\n\n##Usage\n\n###Create a client instance\n\n``` c\n// create a client instance.\npc_client_t *client = pc_client_new();\n  \n```\n\n###Add listeners\n\n``` c\n  // add some event callback.\n  pc_add_listener(client, \"onHey\", on_hey);\n  pc_add_listener(client, PC_EVENT_DISCONNECT, on_close);\n```\n\n###Listener definition\n\n``` c\n// disconnect event callback.\nvoid on_close(pc_client_t *client, const char *event, void *data) {\n  printf(\"client closed: %d.\\n\", client-\u003estate);\n}\n```\n\n###Pomelo defined listeners\n```\n#define PC_EVENT_DISCONNECT \"disconnect\"\n#define PC_EVENT_TIMEOUT \"timeout\"\n#define PC_EVENT_KICK \"onKick\"\n```\n\n###Connect to server\n\n``` c\n  struct sockaddr_in address;\n\n  memset(\u0026address, 0, sizeof(struct sockaddr_in));\n  address.sin_family = AF_INET;\n  address.sin_port = htons(port);\n  address.sin_addr.s_addr = inet_addr(ip);\n\n  // try to connect to server.\n  if(pc_client_connect(client, \u0026address)) {\n    printf(\"fail to connect server.\\n\");\n    pc_client_destroy(client);\n    return 1;\n  }\n ```\n\n###Send a notify\n \n ``` c\n// notified callback\nvoid on_notified(pc_notify_t *req, int status) {\n  if(status == -1) {\n    printf(\"Fail to send notify to server.\\n\");\n  } else {\n    printf(\"Notify finished.\\n\");\n  }\n\n  // release resources\n  json_t *msg = req-\u003emsg;\n  json_decref(msg);\n  pc_notify_destroy(req);\n}\n\n// send a notify\nvoid do_notify(pc_client_t *client) {\n  // compose notify.\n  const char *route = \"connector.helloHandler.hello\";\n  json_t *msg = json_object();\n  json_t *json_str = json_string(\"hello\");\n  json_object_set(msg, \"msg\", json_str);\n  // decref json string\n  json_decref(json_str);\n\n  pc_notify_t *notify = pc_notify_new();\n  pc_notify(client, notify, route, msg, on_notified);\n}\n ```\n\n###Send a request\n \n ``` c\n// request callback\nvoid on_request_cb(pc_request_t *req, int status, json_t *resp) {\n  if(status == -1) {\n    printf(\"Fail to send request to server.\\n\");\n  } else if(status == 0) {\n    char *json_str = json_dumps(resp, 0);\n    if(json_str != NULL) {\n      printf(\"server response: %s\\n\", json_str);\n      free(json_str);\n    }\n  }\n\n  // release relative resource with pc_request_t\n  json_t *msg = req-\u003emsg;\n  pc_client_t *client = req-\u003eclient;\n  json_decref(msg);\n  pc_request_destroy(req);\n\n  // stop client\n  pc_client_stop(client);\n}\n\n// send a request\nvoid do_request(pc_client_t *client) {\n  // compose request\n  const char *route = \"connector.helloHandler.hi\";\n  json_t *msg = json_object();\n  json_t *str = json_string(\"hi~\");\n  json_object_set(msg, \"msg\", str);\n  // decref for json object\n  json_decref(str);\n\n  pc_request_t *request = pc_request_new();\n  pc_request(client, request, route, msg, on_request_cb);\n}\n ```\n \n###More example\n\nThe complete examples: [example/](https://github.com/NetEase/libpomelo/tree/master/example)\n\nTcp server for test: [tcp-pomelo](https://github.com/changchang/tcp-pomelo). \n \n##API\n \nMore information about API, please refer to [pomelo.h](https://github.com/NetEase/libpomelo/blob/master/include/pomelo.h).\n\n\n##Build\n\n###Prerequisite\n\nInstall [GYP](http://code.google.com/p/gyp/source/checkout).\n\n###Mac\n\n```\n./pomelo_gyp\nxcodebuild -project pomelo.xcodeproj\n```\n\n###IOS\n```\n./pomelo_gyp -DTO=ios\n./build_ios\n```\n\n###IOS Simulator\n```\n./pomelo_gyp -DTO=ios\n./build_iossim\n```\n\n###Linux\n```\n./pomelo_gyp\nmake\n```\n\n###Windows\nin your libpomelo project root directory  \nopen git bash and type in  \n```\nmkdir -p build\ngit clone https://github.com/martine/gyp.git build/gyp\n```   \nthen open cmd shell in windows and cd to your libpomelo project root directory  \nand type in  \n```\nbuild\\gyp\\gyp.bat --depth=. pomelo.gyp -Dlibrary=static_library -DTO=pc \n``` \n\nthen open pomelo.sln  in visual studio and you can build libpomelo in windows   \n\n###Cocos2d-x  \n####Android  \njust put libpomelo in ${COCOS2DX-ROOT}/cocos2dx/platform/third_party/android/prebuild path  \nthen in your cocos2d-x android project's root and type in  \n```\n./build_native.sh  \n```\nit will build libpomelo into a .so file and then you can use it in your android application  \n\n###ChatDemo  \n[pomelo-cocos2dchat](https://github.com/NetEase/pomelo-cocos2dchat) you can find more information about using libpomelo in different platforms  \n\n##Notice\n\nThere is a worker thread inside `libpomelo` to run the `libuv` loop and handle the IO events. So all the callback functions are fired in the worker thread. And the application should take care the synchronization between the main thread (such as UI thread) and the `libpomelo` worker thread.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetease%2Flibpomelo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetease%2Flibpomelo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetease%2Flibpomelo/lists"}