E
E
Evgeny Oleinikov2016-05-05 13:02:18
Delphi
Evgeny Oleinikov, 2016-05-05 13:02:18

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;

North
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;

What's wrong here?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey, 2016-05-05
@alsopub

You are trying to read data twice:
1) memo1.lines.add(ClientSocket.Receiveln());
2) c:=strtoint(ClientSocket.Receiveln());
Probably you need to read the input to the variable once, and then work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question