?
Solved

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

Posted on 2003-10-21
7
Medium Priority
?
3,679 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 256 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 248 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 248 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 248 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 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