如果解决网络干扰, 如何解决TcpClient发送完每次都需要断开,TcpServer才能正常响应!(100分)

  • 主题发起人 主题发起人 zengmiao
  • 开始时间 开始时间
Z

zengmiao

Unregistered / Unconfirmed
GUEST, unregistred user!
//这是我写的一个文件传输的模型
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var
FileName, RecvTemp: string;
RecvBuf: pointer;
ReceiveLength, uCmd: integer;
begin
ioctlsocket(ClientSocket.Handle, FIONREAD, ReceiveLength);
GetMem(RecvBuf, ReceiveLength);
Try
ClientSocket.ReceiveBuf(RecvBuf^, ReceiveLength);
RecvTemp := StrPas(PChar(RecvBuf));
If (Length(RecvTemp) >= 8) And (Copy(RecvTemp, 1,7) = 'CT $000') Then
uCmd := StrToInt(Copy(RecvTemp, 4, 5))
else
uCmd := $FFFF;
Case uCmd of
$0000: {File Property}
begin
//接收文件长度等信息
end;
$0001: {Query}
Try
FileName := ExtractFileName(TrimRight(RecvTemp));
RecvFile := TFileStream.Create('C:/Temp/' + FileName, fmCreate);
// ClientSocket.Sendln('CT $0003');
Except
// ClientSocket.Sendln('CT $0002');
end;
$0002: {Refuse};
//拒绝接收
$0003: {Accept}
begin
//接受请求
end;
$0004: ;{Next will be data}
// ClientSocket.Sendln('CT $0005');
$0005: {Data}
begin
end;
$0006: {Abort}
RecvFile.Free;
$0007: {Over}
begin
end;
$0008: {Chat text}
begin
end;
$0009: {end}
RecvFile.Free;
else
RecvFile.WriteBuffer(RecvBuf^, ReceiveLength);
end;
Finally
FreeMem(RecvBuf, ReceiveLength);
end;
end;
 
请各位高手帮帮我!
 
网络干扰:
假如两个客户端同时发信息给主机
假如其它软件向这个端口发送信息, 是不是每条信息都要加上指令

如何实现pcANYWHERE的 Speedsend (TM)技术!

请各位高手指点, 请各位共同参与讨论!
 
后退
顶部