Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have copied some example code for a program that Exchanges data over a network. I am using delphi 7 as my IDE. I get no errors when running the program

I have two seperate applications, one for the server and one for the client.

Here is the Source code for the server:

Delphi
procedure TMainWin.FormCreate(Sender: TObject);
begin
  ServerSocket1.Port := 23;
  ServerSocket1.Active := True;
end;
procedure TMainWin.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ServerSocket1.Active := false;
end;
procedure TMainWin.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  i:integer;
  sRec : string;
begin
  for i := 0 to ServerSocket1.Socket.ActiveConnections-1 do
  begin
    with ServerSocket1.Socket.Connections[i] do
    begin
      sRec := ReceiveText;
      if sRec <> '' then
      begin
        Memo1.Lines.Add(RemoteAddress + ' sends :') ;
        Memo1.Lines.Add(sRec);
      end;
    end;
  end;
end;
procedure TMainWin.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ShowMessage('Client Has Connected');
end;


And for the client:

Delphi
procedure TForm1.FormCreate(Sender: TObject);
begin
  ClientSocket1.Port :=  23;
  //local TCP/IP address of the server
  ClientSocket1.Host :=  '192.168.167.12';
  ClientSocket1.Active :=  true;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  ClientSocket1.Active := false;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
  if ClientSocket1.Active then
    ClientSocket1.Socket.SendText(Edit1.Text);
    ShowMessage('Text Sent ' + Edit1.Text);
end;
procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ShowMessage('Connected');
end;

Kind regards
Posted
Comments
Ron Beyer 15-Jan-14 23:41pm    
Ok, so you have a problem, can you narrow it down? What does it do? What doesn't it do? What is it supposed to do?
Member 10526961 15-Jan-14 23:56pm    
The problem is, The client does not seem to be connecting to the server. I'm very new to this topic so there's a high possibility there's something I've completely missed.
Sergey Alexandrovich Kryukov 15-Jan-14 23:45pm    
How can you expect any functionality? You are not listening for connection, you are not connecting... Or... where?
—SA
Member 10526961 15-Jan-14 23:55pm    
This is all that was provided in the example code. Heres the link: http://delphi.about.com/od/networking/l/aa112602a.htm
Theres still alot of concepts here and keywords that I don't understand, I'm very new to this field.
The example says nothing about connecting so i assumed this was done automatically when using .sendtext
Also, I get no output from the ShowMessage in the ClientSocket1Connect procedure.
Ron Beyer 16-Jan-14 0:03am    
Somehow I doubt your IP address is the same as the one in the article. You will need to change the IP address in the client to match the ip address of the server.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900