metaRTC使用纯C版的websocket实现信令编程
概述
metaRTC除了实现流媒体功能之外,信令功能支持为websocket,metaRTC新版本支持纯C版的websocket。
源代码下载
第三方类库
第三方类库使用的是纯C版的libwebsockets
编程代码
初始化代码
//接收数据回调函数 int g_websocket_receive(void* context,YangSample* data){ ...... return Yang_Ok; } YangWebsocket websock=(YangWebsocket*)calloc(sizeof(YangWebsocket),1); YangWebsocketCallback callback; callback.context=this; callback.receive=g_websocket_receive; yang_create_websocket(websock,&callback);
连接websocket服务器
char* url=(char*)"ws://127.0.0.1:8082/test"; websock->connectServer(websock->context,url); //发送数据 sprintf((char*)test,"this is %d test!",testcount++); websock->sendData(websock->context,(uint8_t*)test,strlen(test));
删除代码
yang_destroy_websocket(websock); yang_free(websock);