Solved

Creating a Delphi7 socket application using the VCL TcpClient and TcpServer components

Posted on 2003-10-21
7
3,398 Views
Last Modified: 2008-03-17
I am trying to create a very simple sockets application using VCL TcpClient and TcpServer and the VCL library but have not been successful. There is a very simple demo app with Delphi7 that uses the CLX library, but I have not found any examples anywhere that use the VCL library. Does anyone have a simple example that they can share?
0
Comment
Question by:muggs007
7 Comments
 
LVL 2

Accepted Solution

by:
philipjc earned 64 total points
ID: 9593768
You might  find it easier to use the TServerSocket and TClientSocket directly.

0
 

Author Comment

by:muggs007
ID: 9595018
Yes, and I have seen simple solutions that use the older TServerSocket and TClientSocket components. I just have not seen any socket apps developed with TcpClient or TcpServer.
0
 
LVL 8

Assisted Solution

by:gmayo
gmayo earned 62 total points
ID: 9597075
What's the advantage of TTCPxxxSocket over TxxxSocket? I have used the latter for several years now and they work fine and are very easy to use.

Geoff M.
0
 
LVL 2

Assisted Solution

by:gangsterboss
gangsterboss earned 62 total points
ID: 9602740
i think with delphi 7, TxxxSocket isn't a component it has been replaced with TTCPxxxSocket
0
 
LVL 2

Assisted Solution

by:alsantos
alsantos earned 62 total points
ID: 9613892
muggs007: I made this sample now, Look this code, you have to create a new applcation, put 2 memo, 3 button, 1 edit , 1 tcpserver and 1 tcpclient.

Button1 will active the server
Button2 will connect the client to the server.
Button3 will send the text on memo2
memo1 will write the text received by the server.

put this code:


// event of tcpserver onAccept
procedure TForm1.TcpServer1Accept(Sender: TObject;
  ClientSocket: TCustomIpClient);
var
  s: string;
begin
  memo1.lines.Add('Remote Host: ' + ClientSocket.RemoteHost +
   ' (' + ClientSocket.RemoteHost + ')');
  s := ClientSocket.Receiveln;
  while s <> '' do
  begin
    memo1.lines.add('Text received: ' + s);
    s := ClientSocket.Receiveln;
  end;
end;

// active the server
procedure TForm1.Button1Click(Sender: TObject);
begin
  TcpServer1.Active := True;
  TcpServer1.LocalPort := '111';
end;

// connect the client to the server
procedure TForm1.Button2Click(Sender: TObject);
begin
  TcpClient1.RemoteHost := edit1.Text;
  TcpClient1.RemotePort := '111';
  if not TcpClient1.Connected then
  begin
    TcpClient1.Connect;
    Button2.Caption:='Disconnect';
  end
  else
  begin
    TcpClient1.Disconnect;
    Button2.Caption := 'Connect';
  end;
end;

// send the text to the server
procedure TForm1.Button3Click(Sender: TObject);
var
  I: Integer;
begin
  if TcpClient1.Connected then
    for I := 0 to memo2.Lines.Count - 1 do
      TcpClient1.Sendln(memo2.Lines[I])
    else showmessage('Not connected.');
end;

Alexandre
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now