Luasocket TCP接收不到数据,why

默认的情况luasocket TCP的函数receive()可以收到在末尾加入’\n’的数据,换一种接收方式receive(‘*a’)却收不到数据,服务端发送的数据在末尾不加入’\n’ 一样也收不到,这是为何呢?

请问楼主解决了吗
我断点可以看到c++有数据,但lua却拿不到?

将cocos2d-x\external\lua\luasocket\buffer.c

下的recvraw 和 recvall修改成下面这样,重新编译后搞定

/-------------------------------------------------------------------------\

  • Reads a fixed number of bytes (buffered)
    *-------------------------------------------------------------------------*/
    static int recvraw(p_buffer buf, size_t wanted, luaL_Buffer *b) {
    int err = IO_DONE;
    size_t total = 0;
    while (err == IO_DONE) {
    size_t count; const char *data;
    err = buffer_get(buf, &data, &count);
    //没有接收到数据,跳出循环
    if (count == 0) {
    if(total > 0 && err == IO_TIMEOUT){
    return IO_DONE;
    }
    break;
    }
    count = MIN(count, wanted - total);
    luaL_addlstring(b, data, count);
    buffer_skip(buf, count);
    total += count;
    if (total >= wanted) break;
    }
    return err;
    }

/-------------------------------------------------------------------------\

  • Reads everything until the connection is closed (buffered)
    *-------------------------------------------------------------------------*/
    static int recvall(p_buffer buf, luaL_Buffer *b) {
    int err = IO_DONE;
    size_t total = 0;
    while (err == IO_DONE) {
    const char *data; size_t count;
    err = buffer_get(buf, &data, &count);
    //没有接收到数据,跳出循环
    if (count == 0) {
    if(total > 0 && err == IO_TIMEOUT){
    return IO_DONE;
    }
    break;
    }
    total += count;
    luaL_addlstring(b, data, count);
    buffer_skip(buf, count);
    }
    if (err == IO_CLOSED) {
    if (total > 0) return IO_DONE;
    else return IO_CLOSED;
    } else return err;
    }