Solved

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

Posted on 2003-10-21
7
3,480 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Intraweb submit form as a POST request 4 355
Correct Component for Shopping Cart. 2 121
shape, triangle, dbctrlgrid 3 31
Delphi, TImage, Png 2 25
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 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