Finishing the Client for an Internet Access Control Application
(Page 1 of 4 )
Last week we began our discussion of the client side of an Internet access control program. This week we'll continue to cover the important parts of the code. We'll start with the reading thread, then go to the ini file. Keep reading to be enlightened.
The reading thread listens for any communication from the server. It will wait for commands from the server for as long as the client is connected and then pass any communication on to the synchronization functions for processing. Here is the code:
constructor TReadingThread.Create(AConn: TIdTCPConnection);
begin
FConn := AConn;
inherited Create(False);
end;
procedure TReadingThread.Execute;
begin
while not Terminated and FConn.Connected do
begin
TLog.AddMsg(FConn.IOHandler.ReadLn);
end;
end;
//**********end message sync functions
procedure TForm1.btnExitClick(Sender: TObject);
begin
close;
end;
When the client is connected, the reading thread is activated and set up:
procedure TForm1.tcConnected(Sender: TObject);
begin
rt := TReadingThread.Create(tc);
end;
procedure TForm1.btnDisconClick(Sender: TObject);
begin
tc.Disconnect;
end;
One of the many actions that is carried out when the client connects is implemented here. First, the client sends over its name and IP address. The btnConnect procedure shows how it is done in code:
procedure TForm1.btnConnectClick(Sender: TObject);
begin
tc.Host:='127.0.0.1';
tc.Port:=1150;
with tc do
begin
try
Connect;
Socket.WriteLn(edname.text+':free@plchldr');
//Socket.WriteLn(GetComputername+':free@plchldr');
except on E : Exception do
showmessage('Could not connect to remote host. Check to see if you entered the right IP address');
end;
end;
end;
procedure TForm1.tcDisconnected(Sender: TObject);
begin
if rt <> nil then
begin
rt.Terminate;
rt.WaitFor;
FreeAndNil(rt);
end;
end;
procedure TForm1.oneClick(Sender: TObject);
var
mins:widestring;
begin
mins:='5'; {
form1.Visible:=false;
form2.times:=strtoint(mins);
form2.label1.caption:=mins;
form2.show; }
//wb.Navigate(path);
end;
Next: Check the ini file >>
More Delphi-Kylix Articles
More By David Web