关于ClientSocket的古怪问题!!!高手请进~~~~~

icyfire129 2003-04-17 11:35:15
我的代码如下:
int port;
AnsiString ip;

ip="10.10.10.10";
port=2250;

ClientSocket1->Address = ip;
ClientSocket1->Port = port;
ClientSocket1->Active = true;
if(ClientSocket1->Socket->Connected )
{
StatusBar1->Panels->Items[0]->Width = 200;
StatusBar1->Panels->Items[0]->Text = "连接 "+ip+" 成功!";

//发送联系报文
BYTE SendBuf[36];
BYTE Recv[300];
SendBuf[0]=1;
。。。。
SendBuf[35] = 0x10;
ClientSocket1->Socket->SendBuf(SendBuf,36);

//检验回送报文
if(ClientSocket1->Socket->ReceiveBuf(Recv,300)>1)
{
if(Recv[0] == 0x02 && Recv[3] == 0x01)
{
StatusBar1->Panels->Items[1]->Text = "接收联系报文成功";
WriteEdit("接收联系报文成功",0);
ClientSocket1->Active = false;
return true;
}
}
问题是,对方接收的报文总是在变的,而我接收到的报文也是在变。应该是不变的。
这个是为什么呢?ClientSocket1设置为阻塞状态。哪位高手指教一下呀~~~~
...全文
41 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
springai 2003-04-17
  • 打赏
  • 举报
回复
if(ClientSocket1->Socket->ReceiveBuf(Recv,300)>1)
应改为
if(ClientSocket1->Socket->ReceiveBuf(Recv,300)==300)
以确定是否收到300个字节的数据
希望通讯时加上校验码
SharpKing515 2003-04-17
  • 打赏
  • 举报
回复
,对方接收的报文总是在变的,而我接收到的报文也是在变。应该是不变的。
//
什么意思啊??不太明白!
lixinwyh 2003-04-17
  • 打赏
  • 举报
回复
在c++builder的目录下面有个例子Examples\Internet\Chat
自己看看吧:)
lixinwyh 2003-04-17
  • 打赏
  • 举报
回复
收到的应该是在onread中,感觉你写得有点乱。
icyfire129 2003-04-17
  • 打赏
  • 举报
回复
哪检验回送报文的时候是不是也要再onWrite中检验?
pp616 2003-04-17
  • 打赏
  • 举报
回复
呵呵
SharpKing515 2003-04-17
  • 打赏
  • 举报
回复
ClientSocket1->Active = true;
//不要立即发送。

//--------
同意!
yesry 2003-04-17
  • 打赏
  • 举报
回复
int port;
AnsiString ip;

ip="10.10.10.10";
port=2250;

ClientSocket1->Address = ip;
ClientSocket1->Port = port;
ClientSocket1->Active = true;
//不要立即发送。
在OnConnect()事件
// if(ClientSocket1->Socket->Connected )
{
StatusBar1->Panels->Items[0]->Width = 200;
StatusBar1->Panels->Items[0]->Text = "连接 "+ip+" 成功!";

//发送联系报文
BYTE SendBuf[36];
BYTE Recv[300];
SendBuf[0]=1;
。。。。
SendBuf[35] = 0x10;
ClientSocket1->Socket->SendBuf(SendBuf,36);

//检验回送报文
if(ClientSocket1->Socket->ReceiveBuf(Recv,300)>1)
{
if(Recv[0] == 0x02 && Recv[3] == 0x01)
{
StatusBar1->Panels->Items[1]->Text = "接收联系报文成功";
WriteEdit("接收联系报文成功",0);
ClientSocket1->Active = false;
return true;
}
}
}

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧