Re: Question on network programming.
From: Maarten Wiltink (maarten_at_kittensandcats.net)
Date: 01/28/05
- Next message: Maarten Wiltink: "Re: Convert C-Builder program to Delphi?"
- Previous message: Tom de Neef: "Re: Referencing a stringlist by name"
- In reply to: chuayongquan_at_hotmail.com: "Question on network programming."
- Next in thread: Vertuas: "Re: Question on network programming."
- Reply: Vertuas: "Re: Question on network programming."
- Reply: VBDis: "Re: Question on network programming."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 28 Jan 2005 19:26:52 +0100
<chuayongquan@hotmail.com> wrote in message
news:1106887214.101221.79300@f14g2000cwb.googlegroups.com...
> I am trying to build a system to let user transfer data and chat using
> Indy.
>
> So it is correct to use 3 IdTCPClient and IdTCPServer:
>
> One for command, one for data and last one for chat??? Or can I reduce
> to 2 IdTCPClient and IdTCPServer.
Been reading the FTP specification, have you? But you can do it with
three, two, or even just one connection between each client and the
central server.
What you need for that is a protocol.
Conceptually, you have several data streams between client and hub.
A protocol is a description of how to mark up, or annotate, data items
so that they can share a single medium and still be distinguishable.
FTP uses data connections because it does _not_ decorate or alter in
any way the data sent over those. One consequence of that is that
closing the data connection prematurely truncates the file and you
have no way of recognising that it wasn't yet finished.
You can make life easy on yourself by designing a protocol that
encodes data items as plain text. It means protocol exchanges are
easy to read; it also means that if you have a server but not yet a
client, you can use Telnet to connect to the server and test it.
Obviously, turning a stream of binary data into plain text incurs
significant overhead. Sometimes, avoiding overhead overrides other
concerns (compare again FTP).
One complication inherent in chatting is that the server can take
the initiative and inform you of news that arrived independently of
your connection with it. It's easier to design a one-way command-reply
protocol. You can design for two-way communication or implement a
little server in each client that has a separate one-way connection
with the hub, on which the hub is the client and issues commands
(messages), and the client is the server and accepts them.
> Then am I correct to use the same IP and three different Port or same
> IP and only one port??? What about using the standard port like 80 or
> 21???
A server listens on a port; a client connects from a local port to a
remote port. The client's remote port must be the server's local port,
and the server will complete the "virtual circuit" by sending replies
to the client's local port as its remote port. The client's local port
is allocated dynamically. The connection is characterised by the full
quadruplet of client IP address and port and server IP address and port.
Only one needs to be different for the connection to be unique; in your
case that would be the client's local port.
If two hosts have several connections between them, they will normally
be between the same two IP addresses, but a host may have several IP
addresses and in the end, communication is between hosts, not interfaces.
The port that the server listens on is very important. It must be known
to a client before it connects, so the biggest assumption of them all
is based on it: what the server will be serving on connections to that
port. The expectation is that a server on port 80 will speak HTTP, and
a server on port 21 FTP. You should not break that expectation lightly.
> If using only one port will there be conflict??? And what about FTP.
> It seem to me that FTP uses only port 21 for command and data transfer.
> So how it is possible to send command and at the same time transfer
> data.
Port 21 is the "well known port" for an FTP server to listen for command
connections. The File Transfer Protocol includes commands to arrange
for data connections to be negotiated between servers and clients, so
when a data connection needs to be made, all parties involved know
where to listen and/or where to connect to.
Groetjes,
Maarten Wiltink
- Next message: Maarten Wiltink: "Re: Convert C-Builder program to Delphi?"
- Previous message: Tom de Neef: "Re: Referencing a stringlist by name"
- In reply to: chuayongquan_at_hotmail.com: "Question on network programming."
- Next in thread: Vertuas: "Re: Question on network programming."
- Reply: Vertuas: "Re: Question on network programming."
- Reply: VBDis: "Re: Question on network programming."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|