Websocket连接回调中引发异常

时间:2018-07-29 05:19:34

标签: linux websocket ubuntu-12.04

在以下代码中:

#define Uses_Info
#define Uses_WebSocketServer
#include "ws.h"

int on_connect(WebSocketServer *server);
void on_message(const char *buf);
void on_disconnect();

void* CALLBACK ws_stream_on_connect(WebSocketServer *server)
{
    Info("ws_stream_on_connect");
    int n = 5;
    server->send(server, MESSAGE_TYPE_BINARY, (unsigned char *)&n, sizeof(int));
    Info("ws after test");
    return server;
    //on_connect(server);
    //return NULL;  // return value is not used in client.
}

size_t CALLBACK ws_stream_on_message(void *plugin_private, const WebSocketServer *server, const int type, unsigned char *buf, const size_t buf_size)
{
    //Info("ws_stream_on_message");
    on_message(buf);
    return 0;
}

void CALLBACK ws_stream_on_disconnect(void *plugin_private, const WebSocketServer *server)
{
    Info("ws_stream_on_disconnect");
    on_disconnect();
}

/*
 * Since we are returning a pointer to static memory, there is no need for a
 * "destroy" function.
 */

static WebSocketPlugin s_plugin = { sizeof(WebSocketPlugin),
                WEBSOCKET_PLUGIN_VERSION_0, NULL, /* destroy */
                ws_stream_on_connect, ws_stream_on_message,
                ws_stream_on_disconnect };

extern EXPORT WebSocketPlugin * CALLBACK ws_stream_init()
{
    Info("ws_stream_init");
    return &s_plugin;
}

我没有“测试后”日志。 Info是将字符串记录在syslog中的函数。我看到“ ws_stream_on_connect”,但没有看到。 有什么问题? 操作系统是Ubuntu 12.04。

0 个答案:

没有答案