Answer the question
In order to leave comments, you need to log in
Why does Delphi server disconnect after the first request?
Good day.
I am writing a client-server application in Delphi, the client must send parameters, the server must process them and send a response. So far, for verification, I have sent a number, the server multiplies it and sends it back. But the server only receives 1 message and shuts down and doesn't respond.
Customer
procedure TForm1.Button1Click(Sender: TObject);
begin
TcpClient1.Open;
TcpClient1.Sendln(Edit1.Text + #10);
ListBox1.Items.Add('< ' + Edit1.Text);
TcpClient1.Close;
end;
procedure TForm1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
var DataLen: Integer);
begin
ListBox1.Items.Add('> ' + TcpClient1.Receiveln());
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TcpServer1.Open;
end;
procedure TForm1.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
var c:integer;
begin
memo1.lines.add(ClientSocket.Receiveln());
c:=strtoint(ClientSocket.Receiveln());
c:=c*5;
TcpServer1.Sendln(inttostr(c)+#10);
end;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question