OMMAND "socket_cmmb_sim_command"
...
fd = socket_local_client(
SOCKET_NAME_CMMB_SIM_COMMAND,
ANDROID_SOCKET_NAMESPACE_ABSTRACT,
SOCK_STREAM );
//check open failed
if (fd < 0)
{
LOGE("Failed to open socket: %s\n\r'", SOCKET_NAME_CMMB_SIM_COMMAND);
goto error;
}
//get command data
p_request.writeInt32 (CMMB_REQUEST_GET_IMSI);
data = (char *)p_request.data();
datasize = (int)p_request.dataSize();
//get command length
dataLength[0] = dataLength[1] = 0;
dataLength[2] = (char)((datasize >> 8) & 0xff);
dataLength[3] = (char)(datasize & 0xff);
//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;
}
...
这样就是实现了客户端和服务器之间的通信。