示例#1
0
static int ClientSendCommandByIp(EmCmdCode emCmdCode, void *pDataBuf,
                             unsigned int u32DataSize, char *pDevIP,
                             unsigned short u16DevPort,
                             bool boIsRespond,  bool boIsEcho,
                             bool boIsReturnSock)
{
    int sock;
    StMsgPkg stMsg, stEchoMsg;

    //给u8DataBuffer字段复制,并计算校验值
    BuildMsg(&stMsg, emCmdCode, pDataBuf, u32DataSize);

    //发送数据到服务器,并接收服务器返回的数据
    sock = TcpClientCommServer(pDevIP, u16DevPort, (char *)&stMsg,
                               sizeof(StMsgPkg), 3000000, boIsRespond,
                               (char *)&stEchoMsg, sizeof(StMsgPkg));
    if (sock < 0)
    {
        LOGERR("TcpClientCommServer error\n");
        return -1;
    }


    if (boIsRespond == TRUE)
    {
        //判断echo是否正确
        if(CheckEcho(&stEchoMsg, emCmdCode))
        {
            LOGERR("CheckEcho error\n");
            return -1;
        }

        if (boIsEcho == TRUE)
        {
            if(u32DataSize == stEchoMsg.u32DataLength)
            {
                memcpy(pDataBuf, stEchoMsg.uoData.u8DataBuffer, u32DataSize);
            }
            else
            {
                LOGERR("receive message data length error\n");
                return -1;
            }
        }
    }

    if (boIsReturnSock == TRUE)
    {
        return sock;
    }
    else
    {
        close(sock);
        return 0;
    }
}
示例#2
0
CTpnsMsgBase* CTpnsMsgManager::GetMsg(uint8_t *buf, size_t len)
{
    if(HEADER_LEN > len)
    {
        return NULL;
    }
    uint8_t cmd;
    int ret = GetCmd(buf, len, cmd);
    CTpnsMsgBase* pMsg = BuildMsg(cmd, buf + HEADER_LEN, len - HEADER_LEN);
    return pMsg;
}
示例#3
0
int EDITAPI EDITLocateError( long lRow, int nCol, int nLen,
                             int resourceid, char *error_msg )
/*********************************************************************/
{
    // queue the request in case the connection to the editor has
    // not fully completed
    if( CurrSession->msg != NULL ) {
        MemFree( CurrSession->msg );
    }
    CurrSession->msg = BuildMsg( lRow, nCol, nLen, resourceid, error_msg );
    if( CurrSession->msg == NULL ) {
        return( FALSE );
    }
    if( CurrSession->hwnd == NULLHANDLE ) {
        // editor session hasn't started yet
        return( FALSE );
    }
    if( !CurrSession->connected ) {
        return( FALSE );
    }
    return( SendData( CurrSession->msg, TRUE ) );
}
示例#4
0
static int ClientSendCommand(EmCmdCode emCmdCode, void *pDataBuf,
                             unsigned int u32DataSize, int s32LoginID,
                             bool boIsRespond,  bool boIsEcho, bool boIsReturnSock)
{
    int ret, sock;
    StMsgPkg stMsg, stEchoMsg;
    stLoginInfo Login;
    unsigned short port;

    ret = GetQueueElem(&s_UserLoginInfoQueue, s32LoginID, &Login);
    if (ret < 0)
    {
        LOGERR("please login\n");
        return -1;
    }

    memset(&stMsg, 0, sizeof(StMsgPkg));
    stMsg.stAccount = Login.stUserAccount;

    //给u8DataBuffer字段复制,并计算校验值
    BuildMsg(&stMsg, emCmdCode, pDataBuf, u32DataSize);

    if (emCmdCode == _CmdPlayCtrl)
    {
        port = STREAM_SERVER_DEFAULT_PORT;
    }
    else
    {
        port = Login.u16DevPort;
    }

    //发送数据到服务器,并接收服务器返回的数据
    sock = TcpClientCommServer(Login.pDevIP, port, (char *)&stMsg,
                               sizeof(StMsgPkg), 3000000, boIsRespond,
                               (char *)&stEchoMsg, sizeof(StMsgPkg));
    if (sock < 0)
    {
        LOGERR("TcpClientCommServer error\n");
        return -1;
    }


    if (boIsRespond == TRUE)
    {
        //判断echo是否正确
        if(CheckEcho(&stEchoMsg, emCmdCode))
        {
            LOGERR("CheckEcho error\n");
            return -1;
        }

        if (boIsEcho == TRUE)
        {
            if(u32DataSize == stEchoMsg.u32DataLength)
            {
                memcpy(pDataBuf, stEchoMsg.uoData.u8DataBuffer, u32DataSize);
            }
            else
            {
                LOGERR("receive message data length error\n");
                return -1;
            }
        }
    }

    if (boIsReturnSock == TRUE)
    {
        return sock;
    }
    else
    {
        close(sock);
        return 0;
    }
}