0
0.5
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ClientSocket: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TestStr: String;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
len:word;
buf:array of char;
msg:string;
begin
Try
ClientSocket.Active := true;
Except
MessageBox(0,'连接失败,请查看服务端是否有启动!','',MB_OK + MB_ICONWARNING);
end;
Msg := TestStr;
Len := Length(Msg);
SetLength(buf,Len);
Move(Msg[1],buf[0],Len);
self.ClientSocket.Socket.SendBuf(buf[0],Len);
end;
procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
len:word;
buf:array of char;
msg:string;
begin
try
len := Socket.ReceiveLength;
setlength(buf, len);
Socket.ReceiveBuf(buf[0], len);
setlength(msg, len);
Move(buf[0], msg[1], len);
self.Memo1.Lines.Add(msg);
except
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TestStr := 'BBBB110270469 8574677 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxEEEE';
end;
end.
以上是我的代码,现在可以正常发送,但是如果服务器端返回的字符串长度过长,则客户端不能完全收到,请问怎么解决?谢谢
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ScktComp, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ClientSocket: TClientSocket;
procedure Button1Click(Sender: TObject);
procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TestStr: String;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
len:word;
buf:array of char;
msg:string;
begin
Try
ClientSocket.Active := true;
Except
MessageBox(0,'连接失败,请查看服务端是否有启动!','',MB_OK + MB_ICONWARNING);
end;
Msg := TestStr;
Len := Length(Msg);
SetLength(buf,Len);
Move(Msg[1],buf[0],Len);
self.ClientSocket.Socket.SendBuf(buf[0],Len);
end;
procedure TForm1.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
len:word;
buf:array of char;
msg:string;
begin
try
len := Socket.ReceiveLength;
setlength(buf, len);
Socket.ReceiveBuf(buf[0], len);
setlength(msg, len);
Move(buf[0], msg[1], len);
self.Memo1.Lines.Add(msg);
except
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TestStr := 'BBBB110270469 8574677 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxEEEE';
end;
end.
以上是我的代码,现在可以正常发送,但是如果服务器端返回的字符串长度过长,则客户端不能完全收到,请问怎么解决?谢谢