zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    UVa 727
    UVa 11495
    UVa 299
    UVa 10194
    UVa 146
    10025
    Tug of War POJ 2576 DP(类似背包)
    Problem A: Freckles UVA 10034 裸生成树
    UVA 562
    CF DIV 2 206 C. Vasya and Robot
  • 原文地址:https://www.cnblogs.com/tester-huang/p/4645955.html
Copyright © 2011-2022 走看看