I am creating a cross platform tcp server using Delphi.
The code is given below.
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
IdCustomTCPServer, IdTCPServer, IdBaseComponent, IdComponent, IdUDPBase, IdContext,
IdSocketHandle, IdUDPServer, FMX.Controls.Presentation, FMX.StdCtrls;
type
TForm1 = class(TForm)
TCPServer: TIdTCPServer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TserverExecute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
var
Binding : TIdSocketHandle;
begin
TCPServer.DefaultPort := 16000;
TCPServer.Bindings.Clear;
Binding := TCPServer.Bindings.Add;
Binding.IP := ‘0.0.0.0’;
Binding.Port := 16000;
end;
procedure TForm1.FormShow(Sender: TObject);
begin
TCPServer.Active := True;
end;
procedure TForm1.TserverExecute(AContext: TIdContext);
Var
C : String;
begin
C:= AContext.Connection.Socket.ReadLn();
if C = ‘TESTSTRING’ then
begin
AContext.Connection.Socket.Writeln(‘SENT’);
end;
end;
end.
The associated fmx file has a TIdTCPServer object TCPServer and a TLabel object Label1
The file is given below.
object Form1: TForm1
Left = 0
Top = 0
Caption = ‘Form1’
ClientHeight = 480
ClientWidth = 640
FormFactor.Width = 320
FormFactor.Height = 480
FormFactor.Devices = [Desktop]
DesignerMasterStyle = 0
object Label1: TLabel
Position.X = 472.000000000000000000
Position.Y = 232.000000000000000000
Size.Width = 144.000000000000000000
Size.Height = 17.000000000000000000
Size.PlatformDefault = False
Text = ‘TCP Server on Port 16000’
end
object TCPServer: TIdTCPServer
Bindings = <>
DefaultPort = 0
MaxConnections = 10
Left = 520
Top = 184
end
end
I currently compile with target Windows64 and run on my PC. I can see the form come up with the label reading TCP Server on Port 16000. If I run netstat on the same machine I don’t see port 16000 being opened.
What is the reason for this.