Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to use TcpServer and TcpClient to realise two computer communication and transfer information?

Posted on 2003-03-19
Medium Priority
Last Modified: 2010-04-04
How to use TcpServer and TcpClient to realise two computer communication and transfer information?
Question by:kousun
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
  • 2

Expert Comment

ID: 8205095
Suggest you use Indy for this. There's a vast number of samples included on exactly your question. If you need a sample poster here, just let me know.

Author Comment

ID: 8207100
Yes ,Can you tell me some difference about the winsocket and the Indy?
I want to exchange some information (such as data or login
information) in two computers within the network,the computer has there own Ip address.

Accepted Solution

chco earned 80 total points
ID: 8208682
Well.. I started using Indy because I needed threaded tcp-data (means basically that you can send and receive multiple data-packets independant from eachother) and Indy also provided easy Socks (proxy) support etc.. so I never really tried Winsock.. Indy was just perfect for me.

If you need to exchange some data, this can be done really easy.. you can for example start an idTCPserver that starts listening and a certain port (say 1025) and have the programm respond to data received there. You could create some kind of protocol yourself or use the Indy command protocol that is also available. If you use the latter than you can pre-define some commands the server should listen for and respond to it.. this is all done visually, so it's easy to understand. Or you can do it manually.. the basics of your program would be something like:

procedure TfrmServer.IdTCPServerExecute(AThread: TIdPeerThread); // the part that get executed when something arrives..
s  : string;
fStream : TFileStream;

s := (AThread.Connection.ReadLn); // this reads whatever came in, prosumably it is a text command, e.g. 'SENDPIC'
if s='SENDPIC' then
    if FileExists('d:\images\test.jpg') then
        // open file stream to image requested
        fStream := TFileStream.Create('d:\images\test.jpg',fmOpenRead + fmShareDenyNone);
        // copy file stream to write stream
        // free the file stream
    AThread.Connection.WriteLn('ERR - Requested file does not exist');

The Client part is not much different.. it is really easy.
Have a look at Indy's demos. The best one is the Image-server demo, it tackles many aspects and is easy to understand..

good luck

Expert Comment

ID: 9316673
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Post your closing recommendations!  No comment means you don't care.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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 this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

705 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