• Stars
    star
    116
  • Rank 303,894 (Top 6 %)
  • Language
    C
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

[DEPRECATED] Please Go to https://github.com/NetEase/libpomelo2

This project is deprecated, please go to https://github.com/NetEase/libpomelo2

##libpomelo

libpomelo is a C language client SDK for Pomelo, supporting the Pomelo protocol definition in Pomelo 0.3 version.

##Dependencies

  • libuv - Cross platform layer, mainly using Network IO and thread.
  • jansson - JSON encode and decode library.

##Usage

###Create a client instance

// create a client instance.
pc_client_t *client = pc_client_new();
  

###Add listeners

  // add some event callback.
  pc_add_listener(client, "onHey", on_hey);
  pc_add_listener(client, PC_EVENT_DISCONNECT, on_close);

###Listener definition

// disconnect event callback.
void on_close(pc_client_t *client, const char *event, void *data) {
  printf("client closed: %d.\n", client->state);
}

###Pomelo defined listeners

#define PC_EVENT_DISCONNECT "disconnect"
#define PC_EVENT_TIMEOUT "timeout"
#define PC_EVENT_KICK "onKick"

###Connect to server

  struct sockaddr_in address;

  memset(&address, 0, sizeof(struct sockaddr_in));
  address.sin_family = AF_INET;
  address.sin_port = htons(port);
  address.sin_addr.s_addr = inet_addr(ip);

  // try to connect to server.
  if(pc_client_connect(client, &address)) {
    printf("fail to connect server.\n");
    pc_client_destroy(client);
    return 1;
  }

###Send a notify

// notified callback
void on_notified(pc_notify_t *req, int status) {
 if(status == -1) {
   printf("Fail to send notify to server.\n");
 } else {
   printf("Notify finished.\n");
 }

 // release resources
 json_t *msg = req->msg;
 json_decref(msg);
 pc_notify_destroy(req);
}

// send a notify
void do_notify(pc_client_t *client) {
 // compose notify.
 const char *route = "connector.helloHandler.hello";
 json_t *msg = json_object();
 json_t *json_str = json_string("hello");
 json_object_set(msg, "msg", json_str);
 // decref json string
 json_decref(json_str);

 pc_notify_t *notify = pc_notify_new();
 pc_notify(client, notify, route, msg, on_notified);
}

###Send a request

// request callback
void on_request_cb(pc_request_t *req, int status, json_t *resp) {
 if(status == -1) {
   printf("Fail to send request to server.\n");
 } else if(status == 0) {
   char *json_str = json_dumps(resp, 0);
   if(json_str != NULL) {
     printf("server response: %s\n", json_str);
     free(json_str);
   }
 }

 // release relative resource with pc_request_t
 json_t *msg = req->msg;
 pc_client_t *client = req->client;
 json_decref(msg);
 pc_request_destroy(req);

 // stop client
 pc_client_stop(client);
}

// send a request
void do_request(pc_client_t *client) {
 // compose request
 const char *route = "connector.helloHandler.hi";
 json_t *msg = json_object();
 json_t *str = json_string("hi~");
 json_object_set(msg, "msg", str);
 // decref for json object
 json_decref(str);

 pc_request_t *request = pc_request_new();
 pc_request(client, request, route, msg, on_request_cb);
}

###More example

The complete examples: example/

Tcp server for test: tcp-pomelo.

##API

More information about API, please refer to pomelo.h.

##Build

###Prerequisite

Install GYP.

###Mac

./pomelo_gyp
xcodebuild -project pomelo.xcodeproj

###IOS

./pomelo_gyp -DTO=ios
./build_ios

###IOS Simulator

./pomelo_gyp -DTO=ios
./build_iossim

###Linux

./pomelo_gyp
make

###Windows in your libpomelo project root directory
open git bash and type in

mkdir -p build
git clone https://github.com/martine/gyp.git build/gyp

then open cmd shell in windows and cd to your libpomelo project root directory
and type in

build\gyp\gyp.bat --depth=. pomelo.gyp -Dlibrary=static_library -DTO=pc 

then open pomelo.sln in visual studio and you can build libpomelo in windows

###Cocos2d-x
####Android
just put libpomelo in ${COCOS2DX-ROOT}/cocos2dx/platform/third_party/android/prebuild path
then in your cocos2d-x android project's root and type in

./build_native.sh  

it will build libpomelo into a .so file and then you can use it in your android application

###ChatDemo
pomelo-cocos2dchat you can find more information about using libpomelo in different platforms

##Notice

There 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.

More Repositories

1

pomelo

A fast,scalable,distributed game server framework for Node.js.
JavaScript
11,871
star
2

tango

A code driven low-code builder, develop low-code app on your codebase.
TypeScript
2,047
star
3

UnitySocketIO

socket.io client for unity3d.
C#
890
star
4

lordofpomelo

the online demo of pomelo
JavaScript
797
star
5

amoro

Amoro is a Lakehouse management system built on open data lake formats.
Java
640
star
6

chatofpomelo

chat application of pomelo
JavaScript
299
star
7

pomelo-unityclient-socket

pomele dotnet client
C#
170
star
8

libpomelo2

A New Client SDK for Pomelo
C
133
star
9

pomelo-unityclient

pomelo client for unity3d.
C#
113
star
10

chatofpomelo-websocket

chatofpomelo with pomelo 0.3.0
JavaScript
101
star
11

pomelo-cocos2d-js

pomelo-cocos2d-js client
JavaScript
101
star
12

arrow

A TestNG plugin with better test report template, re-run tests on failure, and many more.
Java
97
star
13

pomelo-rpc

rpc framework for pomelo
JavaScript
96
star
14

airtest

Deprecated, moved to http://airtest.netease.com
Python
93
star
15

treasures

a tutorial demo of pomelo
JavaScript
90
star
16

pomelo-androidclient

java&android client for pomelo
Java
83
star
17

pomelo-iosclient

iOS client lib for pomelo
Objective-C
68
star
18

pomelo-aoi

The aoi module used in lordofpomelo
JavaScript
59
star
19

pomelo-cocos2dchat

cocos2dchat based on cocos2d-x and libpomelo
C++
57
star
20

pomelo-admin

admin module for pomelo monitor system
JavaScript
51
star
21

pomelo-scheduler

the high performance schedule module for calling scheduled task
JavaScript
50
star
22

pomelo-ioschat

A chat demo for pomelo iOS client
Objective-C
49
star
23

hive-tools

Java
46
star
24

erlyssh

A Parallel SSH Execution Tool
Erlang
44
star
25

pomelo-sync

the backend database sync module
JavaScript
42
star
26

pomelo-robot

the client test framework for websocket
JavaScript
41
star
27

Polyphonic-TrOMR

TrOMR:Transformer-based Polyphonic Optical Music Recognition
Python
41
star
28

pomelo-unitychat-socket

pomelo-chat client based on socket, support unity 3D and other .net environment,
ASP
39
star
29

pomelo-cn

The Chinese issues for pomelo.
38
star
30

pomelo-admin-web

monitor server demo for pomelo admin system
JavaScript
36
star
31

pomelo-bt

behavior tree implementation for pomelo ai
JavaScript
34
star
32

pomelo-cli

pomelo-cli is a command-line library for pomelo maintenance
JavaScript
32
star
33

pomelo-androidchat

chat client application using android client for pomelo
Java
31
star
34

pomelo-robot-demo

pomelo-protocol
JavaScript
31
star
35

pomelo-mqtt-connector

pomelo mqtt connector based on mqtt over tcp and over ws protocol
JavaScript
30
star
36

pomelo-globalchannel-plugin

globalChannel plugin for pomelo
JavaScript
30
star
37

pomelo-protocol

pomelo-protocol
JavaScript
30
star
38

pomelo-logger

logger wrapper of log4js for pomelo logger system
JavaScript
26
star
39

pomelo-status-plugin

status plugin for pomelo
JavaScript
24
star
40

mebius

精准测试sdk
Java
23
star
41

c

Python
20
star
42

pomelo-zookeeper-plugin

zookeeper service for pomelo
JavaScript
19
star
43

nec

Netease's nec css framework,
CSS
18
star
44

pomelo-unitychat

ASP
17
star
45

opencurve

14
star
46

pomelo-sync-plugin

sync plugin for pomelo
JavaScript
14
star
47

pomelo-rpc-zeromq

pomelo rpc using zeromq for communication
JavaScript
13
star
48

tango-boot

A frontend framework for netease tango low-code app
TypeScript
12
star
49

pomelo-protobuf-plugin

plugin for pomelo protobuf
JavaScript
12
star
50

lakehouse-benchmark

A benchmark tool for lakehouses.
Java
11
star
51

pomelo-pathfinding

Path finding module used in lordofpomelo.
JavaScript
10
star
52

tango-components

An UI library for tango low-code builder
TypeScript
10
star
53

pomelo-dotnetchat-console

pomelo-chat client based on socket and .net
C#
10
star
54

pomelo-loader

loader module for pomelo to load handler and remote with the convention over configuration rules
JavaScript
10
star
55

example

C
9
star
56

pomelo-daemon

provide daemon process service for pomelo to deploy in distributed environments
JavaScript
9
star
57

ranger

Java
9
star
58

pomelo-scale-plugin

scale up service for pomelo
JavaScript
7
star
59

pomelo-masterha-plugin

master ha plugin for pomelo
JavaScript
7
star
60

pomelo-data-plugin

load data pomelo plugin
JavaScript
6
star
61

kyuubi-arctic-playground

Playbook of Kyuubi and Arctic Demo
Dockerfile
6
star
62

tango-playground

A playground app of tango low-code builder
TypeScript
5
star
63

pomelo-monitor

Simple, comprehensive monitoring tool for operating-system and process in nodejs.
JavaScript
5
star
64

lakehouse-benchmark-ingestion

A ingestion tool for Lakehouse benchmark
Java
4
star
65

pomelo-collection

Collection used for pomelo
JavaScript
4
star
66

airtest-gui

GUI write by qt for airtest
Python
3
star
67

pomelo-data-plugin-demo

pomelo-data-plugin demo
JavaScript
3
star
68

tango-site

Official site of NetEase Tango low-code builder
TypeScript
3
star
69

amoro-site

Documentation site for project Amoro
SCSS
2
star
70

amoro-medium

Medium materials for project Amoro
1
star