W
windlike
Unregistered / Unconfirmed
GUEST, unregistred user!
用C++Builder4.0(与Delphi应该是差不多的)编了一个阻塞的应用.ServerSocket为stThreadBlocking,ClientSocket为ctBlocking.
Client端先发送一个命令(2byte长)给Server,Server接受命令,并
发回数据给Client端。程序如下。
Client:
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
char buf[2];
strncpy(buf,Edit2->Text.c_str(),2);
ClientSocket1->Open();
TWinSocketStream * pStream = new TWinSocketStream(ClientSocket1->Socket,60000);
int i;
i=pStream->Write((void*)buf,2);
delete pStream;
}
执行完可以看到i=2.
Server端如下:
void __fastcall TMainForm::ServerSocket1GetThread(TObject *Sender,
TServerClientWinSocket *ClientSocket,
TServerClientThread *&SocketThread)
{
char *Buffer;
char Command[2];
char *SendBuf;
int size;
TWinSocketStream *pStream = new TWinSocketStream(ClientSocket1->Socket,60000);
size = pStream->Size;
Buffer =(char *)malloc(pStream->Size);
if (!pStream->WaitForData(60000)){
delete pStream;//每次都进这里了
return;
}
pStream->Read(Buffer,pStream->Size);
。。。
}
执行到这里size为0.然后每次都在if处进去了
pStream->Read执行不了。
到底怎么回事呢?
请各位高人指点。
多谢了。越快越好
Client端先发送一个命令(2byte长)给Server,Server接受命令,并
发回数据给Client端。程序如下。
Client:
void __fastcall TMainForm::Button2Click(TObject *Sender)
{
char buf[2];
strncpy(buf,Edit2->Text.c_str(),2);
ClientSocket1->Open();
TWinSocketStream * pStream = new TWinSocketStream(ClientSocket1->Socket,60000);
int i;
i=pStream->Write((void*)buf,2);
delete pStream;
}
执行完可以看到i=2.
Server端如下:
void __fastcall TMainForm::ServerSocket1GetThread(TObject *Sender,
TServerClientWinSocket *ClientSocket,
TServerClientThread *&SocketThread)
{
char *Buffer;
char Command[2];
char *SendBuf;
int size;
TWinSocketStream *pStream = new TWinSocketStream(ClientSocket1->Socket,60000);
size = pStream->Size;
Buffer =(char *)malloc(pStream->Size);
if (!pStream->WaitForData(60000)){
delete pStream;//每次都进这里了
return;
}
pStream->Read(Buffer,pStream->Size);
。。。
}
执行到这里size为0.然后每次都在if处进去了
pStream->Read执行不了。
到底怎么回事呢?
请各位高人指点。
多谢了。越快越好