Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

636 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