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

x
?
Solved

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

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

Expert Comment

by:chco
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.
0
 

Author Comment

by:kousun
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.
0
 

Accepted Solution

by:
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..
var
s  : string;
fStream : TFileStream;

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

----------------------------
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
0
 

Expert Comment

by:CleanupPing
ID: 9316673
kousun:
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 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

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