A
archy
Unregistered / Unconfirmed
GUEST, unregistred user!
一个server/client通讯程序,client中单击btn1激发
var str1,str2:string;
str1=:'abcdefg'; str2:='2';
clientsocket1.Socket.SendText(str1);
clientsocket1.socket.SendText(str2);
server中用两个Socket.ReceiveText如此接受
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var str1,str2:string;
if receivecount<1 then // str1,str2初值为空'',receivecount=0;
begin
str1:=Socket.ReceiveText;
inc(receivecount);
end
else
begin
str2:=Socket.ReceiveText;
memo2.Clear;
memo2.Lines.Append(str1);
memo2.Lines.Append(str2);
receivecount:=0;
str1:=''; str2:='';
end;
我发现一个十分奇怪的问题,若我click btn1很快2下(相当于双击),则server的memo2中会显示
abcdefg2
abcdefg
很明显client的第一次的clientsocket1.Socket.SendText(str1);
clientsocket1.socket.SendText(str2);
因传送太快被server的第一个一个str1:=Socket.ReceiveText;统统吃掉了,
第二次的clientsocket1.Socket.SendText(str1);则被server中的str2:=Socket.ReceiveText;接收,
而第二次的clientsocket1.socket.SendText(str2);则丢失了
若我click btn1较慢两下或一下,则server的memo2中会正确的显示
abcdefg
2
我要的结果
百思不得其解,调试也看不出端倪,恳请高手指教望,怎样避免此种情况呢?
var str1,str2:string;
str1=:'abcdefg'; str2:='2';
clientsocket1.Socket.SendText(str1);
clientsocket1.socket.SendText(str2);
server中用两个Socket.ReceiveText如此接受
procedure ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var str1,str2:string;
if receivecount<1 then // str1,str2初值为空'',receivecount=0;
begin
str1:=Socket.ReceiveText;
inc(receivecount);
end
else
begin
str2:=Socket.ReceiveText;
memo2.Clear;
memo2.Lines.Append(str1);
memo2.Lines.Append(str2);
receivecount:=0;
str1:=''; str2:='';
end;
我发现一个十分奇怪的问题,若我click btn1很快2下(相当于双击),则server的memo2中会显示
abcdefg2
abcdefg
很明显client的第一次的clientsocket1.Socket.SendText(str1);
clientsocket1.socket.SendText(str2);
因传送太快被server的第一个一个str1:=Socket.ReceiveText;统统吃掉了,
第二次的clientsocket1.Socket.SendText(str1);则被server中的str2:=Socket.ReceiveText;接收,
而第二次的clientsocket1.socket.SendText(str2);则丢失了
若我click btn1较慢两下或一下,则server的memo2中会正确的显示
abcdefg
2
我要的结果
百思不得其解,调试也看不出端倪,恳请高手指教望,怎样避免此种情况呢?