Unable to send text (string) from ttcpserver to ttcpclientserver

I have 2 forms, 1 for another server for the client. After resetting ttcpserver on the server form and setting its localhost property to 127.0.0.1 and the localport property to 55555 and the Active property to true, I wrote the on1click (sendtextbutton) button:

procedure TForm2.Button1Click(Sender: TObject);
begin
      TcpServer1.Sendln('message');
end;

Then, on the client form, I dropped 1 ttcpclient 1 shortcut 2 buttons, set the remote host property 127.0.0.1 for the client and the remote port to 55555, wrote an event handler for connectbutton (button1):

procedure TForm2.Button1Click(Sender: TObject);
begin
try
TcpClient1.Active := true;
except
showmessage('error');

end;
end;

Wrote the onconnect event for ttcpclient:

procedure TForm2.TcpClient1Connect(Sender: TObject);
begin
    Label1.Caption := 'connected!';
end;

and then finally onrecieve eventler for ttcpclient:

procedure TForm2.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
  var DataLen: Integer);
begin
    Label1.caption := TcpClient1.Receiveln();
end;

, "" ( ), . ? , ? (, !)

+3
2

TTcpServer , .

TidTcpServer TidTcpClient. TidTcpServer Context, , , , , , .

TidTcpServer TIdTcpClient:

+2

, TTcpServer.SendLn() . - .

TTcpServer.BlockMode bmThreadBlocking ( ), TTcpServer.BlockMode - , TTcpServer.Accept(), TTcpServer.OnAccept. , , , , , .

, TTcpServer.BlockMode bmBlocking bmNonBlocking, TTcpServer.Accept(), TCustomIpClient. , TTcpServer.OnAccept , , , .

+1

Source: https://habr.com/ru/post/1753338/


All Articles