不要用ReceiveText()函数,感觉它不受阻塞影响。即使设置成阻塞模式,它也是调用就返回,没有数据就返回为空。
官方文档里说,阻塞模式要用
TWinSocketStream *pClientStream;//TWinSocketStream to read or write information over a blocking socket connection
pClientStream=new TWinSocketStream(ClientSocket1->Socket,TIMEOUT);
求人不如求己,这末简单的问题还不如自己查帮助:
recv function
The recv function receives data from a connected socket or a bound connectionless socket.
Syntax
int recv(
_In_ SOCKET s,
_Out_ char *buf,
_In_ int len,
_In_ int flags
);
Parameters
s [in]
The descriptor that identifies a connected socket.
buf [out]
A pointer to the buffer to receive the incoming data.
len [in]
The length, in bytes, of the buffer pointed to by the buf parameter.
flags [in]
A set of flags that influences the behavior of this function. See remarks below. See the Remarks section for details on the possible value for this parameter.
Return value
If no error occurs, recv returns the number of bytes received and the buffer pointed to by the buf parameter will contain this data received. If the connection has been gracefully closed, the return value is zero.
摘自MSDN。