Z
zzitwang
Unregistered / Unconfirmed
GUEST, unregistred user!
現在我想用TclientSocket給一服務器發送些數據,數據的多少不固定,而且我要接收服務器反回的信息!
var
csocket:TclientSocket;
data:string;
procedure TForm1.Button2Click(Sender: TObject);
var
log:integer;
i:integer;
begin
log:=length(memo1.lines.count);
for i:=0 to log-1 do
begin
data:= memo1.Lines.Strings;//發送的數據
csocket.Host:=hosturl;
csocket.Port :=hostport;
csocket.Open;
{這裡怎麼寫等待的代碼?
如果寫成
while true do
application.ProcessMessages();
那麼TClientSocket只發送一條數據就不再發了
為什麼?}
end;
end;
procedure TForm1.csocketConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
socket.SendText(data);
end;
procedure TForm1.csocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
errorcode:=0;socket.Close;
end;
procedure TForm1.csocketRead(Sender: TObject; Socket: TCustomWinSocket);
begin
memo2.Text:=Memo2.text+socket.ReceiveText;
end;
var
csocket:TclientSocket;
data:string;
procedure TForm1.Button2Click(Sender: TObject);
var
log:integer;
i:integer;
begin
log:=length(memo1.lines.count);
for i:=0 to log-1 do
begin
data:= memo1.Lines.Strings;//發送的數據
csocket.Host:=hosturl;
csocket.Port :=hostport;
csocket.Open;
{這裡怎麼寫等待的代碼?
如果寫成
while true do
application.ProcessMessages();
那麼TClientSocket只發送一條數據就不再發了
為什麼?}
end;
end;
procedure TForm1.csocketConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
socket.SendText(data);
end;
procedure TForm1.csocketError(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
errorcode:=0;socket.Close;
end;
procedure TForm1.csocketRead(Sender: TObject; Socket: TCustomWinSocket);
begin
memo2.Text:=Memo2.text+socket.ReceiveText;
end;