TIdTcpServer 到底怎么获取待读缓冲去的大小,这个AThread.Connection.ReadFromStack(false,100,false);老是有这个两个异常(‘Not Connected’和‘Disconnected’)。怎么办啊?
解决方案 »
- 用qreport如何打印下面這種格式的報表!
- 请教pascal的一个问题,
- 请教:Resize事件出错
- 关于delphi自动保存工程的问题
- 一句SQL SERVER的SQL语句翻译成ACCESS的SQL语句的问题,内详!
- 大富翁怎么上不了了?
- 请问如何判断ListView中是否存在某listItem
- 一个数据库转换的问题;将Delphi2下建立的PARADOX库转换到Delphi6下的问题,估计是BDE的问题怎么来解决呢???
- 突然看不到前途...
- 在线等待,fastreport表画法(第一列合并)
- 如何获得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;