在Android上使用LocalSocket实现上层Java和底层C++的通(3)

//write command getimsi length
    if(SmsMbbmsSimSocketWrite(fd, dataLength, sizeof(dataLength)) != sizeof(dataLength))
    {
        LOGE("Failed to write cmmand %d 's length to socket: %s!!!!!\n'", CMMB_REQUEST_GET_IMSI, SOCKET_NAME_CMMB_SIM_COMMAND);
        goto error;
    }

//write command getimsi
    if(SmsMbbmsSimSocketWrite(fd, data, datasize) != datasize)
    {
        LOGE("Failed to write cmmand %d to socket: %s!!!!\n'", CMMB_REQUEST_GET_IMSI, SOCKET_NAME_CMMB_SIM_COMMAND);
        goto error;
    }
    //write end, start read response
    //read head, include length of data, 4 byte
    if(SmsMbbmsSimSocketRead(fd, response_data, 4) != 4)
    {
        LOGE("Failed to read response command %d 's length from socket: %s!!!!!\n'", CMMB_REQUEST_GET_IMSI, SOCKET_NAME_CMMB_SIM_COMMAND);
        goto error;
    }
    //LOGD("response_data of length: %d, %d, %d, %d!!!\n", response_data[0], response_data[1], response_data[2], response_data[3]);
    //calculate length
    response_length = ((response_data[0] & 0xff) << 24)
                    | ((response_data[1] & 0xff) << 16)
                    | ((response_data[2] & 0xff) << 8)
                    | (response_data[3] & 0xff);
    //LOGD("response_length = %d\n", response_length);
    //check length
    if(response_length == 0)
    {
        LOGE("response %d 's length from socket: %s is not right!!!!!\n'", CMMB_REQUEST_GET_IMSI, SOCKET_NAME_CMMB_SIM_COMMAND);
        goto error;
    }
...

这样就是实现了客户端和服务器之间的通信。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/pxdyz.html