Hi I have a problem with the following code:
program client;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, System.Win.ScktComp, idContext, idGlobal;
var
ClientSocket1: TClientSocket;
m: TMethod;
m2: TMethod;
procedure hi(Sender: TObject; Socket: TCustomWinSocket);
begin
ClientSocket1.Socket.SendText('hello');
Writeln('connect');
end;
Procedure read_data(Sender: TObject; Socket: TCustomWinSocket);
Var
Raw: String;
Begin
Raw := Socket.ReceiveText;
Writeln(Raw);
End;
begin
try
ClientSocket1 := TClientSocket.Create(nil);
ClientSocket1.Address := '127.0.0.1';
ClientSocket1.Port := 123;
ClientSocket1.Open;
m.Code := @read_data;
m.Data := ClientSocket1;
ClientSocket1.OnRead := TSocketNotifyEvent(m);
m2.Code := @hi;
m2.Data := ClientSocket1;
ClientSocket1.OnConnect := TSocketNotifyEvent(m2);
while '1' = '1' do
begin
//
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
The problem is not receiving any information from the server and when connected correctly not detected in the program. The program is a console application to connect using the ClientSocket component.
the server program is run in a graphical application and uses the ServerSocket component enabled port 123, use these buttons:
procedure TForm1.Button1Click(Sender: TObject);
begin
ServerSocket1.Socket.Connections[ListBox1.Itemindex].SendText(Edit1.Text);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
lugar: Integer;
begin
ListBox1.Clear;
for lugar := 0 To ServerSocket1.Socket.ActiveConnections - 1 do
begin
ListBox1.Items.add(ServerSocket1.Socket.Connections[lugar].RemoteHost);
end;
end;
Can someone help me?