TIdTcpServer 到底怎么获取待读缓冲去的大小,这个AThread.Connection.ReadFromStack(false,100,false);老是有这个两个异常(‘Not Connected’和‘Disconnected’)。怎么办啊?
解决方案 »
- 树的遍历问题,老牛请进啊,我想的发晕了,还是有点问题! 解决100分相送!
- 利用DELPHI模拟点击某网页上的按钮问题
- 操作方法修改...請大家學雷峰多提點子!
- 设置焦点的问题?
- 过年了,分数太多,散点分之1
- 这是什么错误啊(关于sql的)
- @@@@@ D5程序升级到D6时出现严重错误。你能解决吗?因为觉得几乎没有解决的希望,所以也不给高分了。 // adailee 2002-04-28
- 各位大位,有谁用过RM做报表?小弟这里出了点问题!在线等待!
- 在两个页面修改数据库中的记录,如何使修改后的是原记录而不是实现了增加的效果
- Delphi5的language的详细使用方法?
- 如何获得ACTIVE控件ShockwaveFlash的鼠标单击事件
- 用另外一个线程去打开ADOQUERY,显示在DBGRID上,有问题。咨询
procedure TRecThread.Execute;
var
ires,i,j : integer;
recMsg : TMyMsg;
stmp : String;
sNode,ss : TTreeNode;
begin
{ Place thread code here }
FreeOnTerminate := True; while ((not Terminated) and DM.tcpLog.Connected) do
begin
ires := DM.tcpLog.ReadFromStack(...);
if ires > 0 then
begin
用的是9.00.10版本
不过我ires := DM.tcpLog.ReadFromStack(...)里面没加参数
ReadFromStack不要参数没有数据读的时候有‘Read Timeout’异常。
我是用的9.00.10(Delphi7自带的)。我就是要实现取得待缓冲区的大小,然后一次读出来。
你能不能把这方面的代码贴出来我参考一下,谢谢。QQ:69786714
procedure TRecThread.Execute;
var
ires,i,j : integer;
recMsg : TMyMsg;
stmp,tmpName,tmpRealName,tmpDept,pointDept : String;
sNode,ss : TTreeNode;
begin
{ Place thread code here }
FreeOnTerminate := True; while ((not Terminated) and DM.tcpLog.Connected) do
begin
ires := DM.tcpLog.ReadFromStack;
if ires > 0 then
begin
DM.tcpLog.ReadBuffer(recMsg,sizeof(recMsg));
case recMsg.iType of
3 : // 接收信息(说话)
begin
procedure Tfrm_ServerMain.TCPServerExecute(AThread: TIdPeerThread);
var
sMyMsg,sSendMsg,sChangeStatMsg,sFindFriend,sSelfMsg : TMyMsg;
stmp : String[50];
sRealName : String;
i,iindex : integer;
mythread : TIdPeerThread;
friendsList,OnlineFriendList : TStringList; MyFriendMsg : TFriendMsg;
fileStream : TMemoryStream;
begin if (not AThread.Terminated) and (AThread.Connection.Connected) then
begin
AThread.Connection.ReadBuffer(sMyMsg,sizeof(sMyMsg));
case sMyMsg.iType of
1 : //登录
begin
现在就在得到缓冲区大小的异常,用这个(AThread.Connection.ReadFromStack(false,100,false))取大小的。我估计这个异常是我服务端强制断开客户端后才产生的。怎么能让它不产生异常呢?
强制断开后可能还在OnExecute读大小,我想是不是这个原因哦?断开以后还是可以接收其他客户端的数据。
看看我的连接和断开代码
procedure Tfrm_ServerMain.TCPServerConnect(AThread: TIdPeerThread);
begin
iUserCount := iUserCount + 1;
stbMain.Panels[0].Text := '连接用户个数:' + IntToStr(iUserCount); MyList.LockList.Add(Pointer(AThread));
MyList.UnlockList;
AThread.FreeOnTerminate := True;
end;procedure Tfrm_ServerMain.TCPServerDisconnect(AThread: TIdPeerThread);
var
i : integer;
SetStatMsg : TMyMsg;
begin
iUserCount := iUserCount - 1;
stbMain.Panels[0].Text := '连接用户个数:' + IntToStr(iUserCount); if AThread.Data <> nil then
begin { qryDisconn.Close;
qryDisconn.SQL.Text := 'Select * from tb_User a, tb_Friends b '
+ 'where a.fUserName = b.fFriendsName and a.fstat = 0 and b.fUsername = ' + QuotedStr(TFriendMsg(AThread.Data).UserName);
qryDisconn.Open; }
qryDisconn.Close;
qryDisconn.SQL.Text := 'Select * from tb_User where '
+ ' fstat <> 9 and fUsername <> ' + QuotedStr(TFriendMsg(AThread.Data).UserName);
qryDisconn.Open;
if qryDisconn.RecordCount > 0 then
begin
qryDisconn.First;
while not qryDisconn.Eof do
begin
SetStatMsg.iType := 2;
SetStatMsg.iFile := 0;
SetStatMsg.iSize := 0;
SetStatMsg.istat := 9;
SetStatMsg.Pwd := '';
SetStatMsg.RecName := qryDisconn.FieldValues['fUserName'];
SetStatMsg.UserName := TFriendMsg(AThread.Data).UserName;
SetStatMsg.sIP := '';
SetStatMsg.sMsg := '';
i := lbxUser.Items.IndexOf(qryDisconn.FieldValues['fUserName']);
TIdPeerThread(MyList.LockList.Items[i]).Connection.WriteBuffer(SetStatMsg,sizeof(SetStatMsg),True);
MyList.UnlockList;
qryDisconn.Next;
end;
end; if qryMain.Locate('fUserName',TFriendMsg(AThread.Data).UserName,[]) then //用户下线
begin
qryMain.Edit;
qryMain.FieldValues['fStat'] := 9;
qryMain.FieldValues['fLogIP'] := '';
qryMain.Post;
end; AThread.Data := nil;
end; i := MyList.LockList.IndexOf(Pointer(AThread));
MyList.UnlockList;
MyList.LockList.Remove(Pointer(AThread));
MyList.UnlockList; //AThread.Free;
lbxUser.Items.Delete(i);
end;