LR socket接收数据 标准函数,结构体解析

 

//接收 
DWORD RecvBuf(char* cRecvBuf,char* cSocketName,char* cBufName)
{
    int ret=0;
    char * cRecvdata=0;
    int iRecvdatalen=0;
    DWORD begin=0,cur=0;
    begin=clock();
    while(1)
    {
        ret=lrs_receive(cSocketName,cBufName,LrsLastArg);    
        switch(ret)
        {
        case 0:
        case LRS_RECV_MISMATCH :
            ret=lrs_get_last_received_buffer(cSocketName,&cRecvdata,&iRecvdatalen);
            if(ret)
            {
                lr_error_message("last_recv获取接收缓冲区出错,错误码:%d",ret);
                lrs_free_buffer(cRecvdata);
                return ERROR;
            }
            if(iRecvdatalen)
            {
memcpy(cRecvBuf,cRecvdata,iRecvdatalen);
                lrs_free_buffer(cRecvdata);
                return SUCCESS;
            }
            cur=clock();
            if((cur-begin)>=10000)
            {
                lr_error_message ("接收超时,接收等待时间=%d毫秒",cur-begin);
                return ERROR;
            }
            continue;
        default:
            lr_error_message ("recv接收数据出错,错误码:%d",ret);
            return ERROR;
        }//end switch
    }//end while
    return SUCCESS;

 

 

ret=RecvBuf(cRecvBuf,"socket0","buf10");
lr_error_message("get string :%s",cRecvBuf);
pHead=(Head *)cRecvBuf;
lr_error_message("get string :%d",pHead->iPackageType);

注:需要在data里注意  


recv buf10 12

posted @ 2015-07-14 17:04  耀yao  阅读(352)  评论(0编辑  收藏  举报