Greetings, I am trying to program something to distribute my hosts file to computers over a LAN or WAN as an example of a good client server program. For those of you who don't know what the hosts file is, it's a handy file that can block ads or make shortcuts to domains (like if you wanted to go to devshed.com, you could make it so typing "d" could go to devshed.com). However, I get two errors, "asynchronous socket error 10049" from the file placed on the client, and an error about trying to send or receive data while not connected on the server. The client program runs a timer that tries to connect to the server, it's on a timer in case the server is down. Heres the source code for the client:
Code:
unit Unit1;

interface

uses
  Windows, Registry, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ScktComp, ExtCtrls, CheckPrevious;

type
  TForm1 = class(TForm)
    c: TClientSocket;
    Timer1: TTimer;
    procedure FormCreate(Sender: TObject);
    procedure cConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure cRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure Timer1Timer(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

const
name = 'TestComp';
var
  Form1: TForm1;
  SysDir: array[0..MAX_PATH + 1] of char;
  Path: String;
  data:TStringList;
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Application.ShowMainForm := False; // Theirs no form to show
if application.exename <> String(SysDir + '\hostsmanager.exe') then
begin
WinExec(PChar(SysDir + '\hostsmanager.exe'), SW_HIDE);
application.Terminate;
end;
  if CheckPrevious.RestoreIfRunning(Application.Handle) then
  begin
  application.Terminate;
  end;

timer1.Enabled := true;


end;

procedure TForm1.cConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
c.Socket.SendText(name);
end;

procedure TForm1.cRead(Sender: TObject; Socket: TCustomWinSocket);
begin
while c.Socket.ReceiveText <> 'END' do
  data.Add(c.Socket.ReceiveText);
data.SaveToFile('c:\windows\hosts');
data.SaveToFile('c:\winnt\system32\drivers\etc\hosts');
data.SaveToFile('c:\windows\system32\drivers\etc\hosts');
c.Socket.Close;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
if c.Socket.Connected = false then
c.Open;
end;

end.
and the server

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ScktComp;

type
  TForm1 = class(TForm)
    s: TServerSocket;
    procedure sClientRead(Sender: TObject; Socket: TCustomWinSocket);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.sClientRead(Sender: TObject; Socket: TCustomWinSocket);
var
name:PChar;
ip:PChar;
data:TStringList;
i:integer;
begin
data := TStringList.Create;
ip := PChar(s.Socket.RemoteHost);
name := PChar(s.Socket.ReceiveText);
ShowMessage(name + ' ' + '(' + ip + ')' + ' has connected');
if MessageBox(HWND(application.MainForm), PChar('Send hosts file to ' + name + ' ?'), PChar('Send hosts file to ' + name + ' ?'), MB_YESNO) = ID_YES then
  data.LoadFromFile(ExtractFilePath(Application.ExeName) + 'hosts.txt');
for i := 1 to data.Count do
  s.Socket.SendText(data[i]);
s.Socket.SendText('END');
end;

end.