2013-08-16 88 views
0

所述的Labwindows文檔說以下有關ServerTCPRead方法:labwindows:ServerTCPRead究竟需要什麼參數?

int ServerTCPRead (unsigned int conversationHandle, void *dataBuffer, size_t dataSize, unsigned int timeOut); 

DataBuffer中無效*指針到緩衝器在其中存儲的數據。

然而,當我真正聲明指針,並將它傳遞給方法,它具有以下錯誤返回:

FATAL RUN-TIME ERROR: "test1.c", line 146, col 61, thread id 0x00001474: Array argument too small (1 bytes). Argument must contain at least 60000 bytes (60000 elements).

這裏是我使用的代碼:

char * receiveBuf=""; 
    ssize_t dataSize = 60000; 

    switch (event) 
     { 
     case TCP_CONNECT: 

      break; 
     case TCP_DATAREADY: 
      if ((dataSize = ServerTCPRead (g_hconversation, receiveBuf, 
              dataSize, 1000)) 
       < 0) 
       { 
       //SetCtrlVal (g_hmainPanel, MAINPNL_RECEIVE, "Receive Error\n"); 

       } 
      else 
       { 
      display_value_from_client(receiveBuf); 

       }            
      break; 

回答

1

你有將receiveBuf分配爲空字符串,因此沒有空間來存儲您將在函數調用中接收到的數據。我會

ssize_t dataSize = 60000; 
char * receiveBuf = malloc(dataSize); 

更換

char * receiveBuf=""; 
ssize_t dataSize = 60000; 

,不要忘記根據需要自由再打。

也基於錯誤,這個調用可能會阻塞,直到它收到dataSize字節。你應該檢查文檔。