Title: Advanced Java Programming: programming of distributed application using TCPIP
1Advanced Java Programming programming of
distributed application using TCP/IP
- Tokyo, Feb. 2007
- Nelson Baloian,
- Teaching assistant Roberto Konow
2Content
- 0. Introduction (concepts of distributed systems)
- 1. TCP/IP client server programming
- Client programming
- a simple client (date, echo)
- a pop3 client
- A SMTP client
- 2. Server programming (and their clients)
- Simple client-server example with serializing
example - File Servers simple whole file iterative server
(not secure) - Simple whole file robust server
- Simple whole file concurrent server
- Stateless random access file server
- TCP/IP Chat with awareness
- A simple extensible web server
- Parallel downloading techniques
- Awareness in a TC/IP peer to peer environment and
the latecomers problem
3Content
- 3. UDP programming
- simple UDP client-server example
- a "ping" program
- multicasting
- multicasting chat
- awareness in a multicasting environment
- broadcasting vs. multicasting
- 4. RMI Client-server programming
- a simple example will be used to show
remiregistry, concurrency automatic stub
distribution - a sequential file server with state
- Automatic teller machine example
- RMI-based chat with awareness
- 5- Introduction to servlets and jsp
- principles - parameters (from request and
parameter file) - using forms
- implementing state with cookies/sessions
- 6- JDBC
4Evaluation
- Attending to classes (at least 80)
- Homeworks (5)
5Why distributed systems
- - Share resources (25 years ago)
- - Communicate people (now)
- Performance, scalability (always)
- Fault tolerant systems (always)
6Which distributed programs do I use daily ?
1- ICQ 2- email 3- p2p file sharing 4- web
browser-server 5- database software 6- file
server
7Can we deduce how were they developed ?
1- Programming language and resources used 2-
Connection style 3- Communications
architecture 4- Software architecture 5- Server
design (if any)
8Internet two different ways to deliver a
message to another application
Applications programmers decide on this
according to their needs
The UDP User Defined Package like writing a
letter
TCP or UDP
9Every layer has the illusion of talking to the
same one located at the other host
The UDP User Defined Package like writing a
letter
Read write sequence
4444
UDP or TCP communication
Internet frames and addresses
electric pulses
10Implementation of Communications in a TCP/IP
Network
- At a low level (future assembler of the
communications?)
- Based on the sockets ports abstractions
- Originally developed for BSD UNIX but now
present in almost all systems (UNIX, LINUX,
Macintosh OS, Windows) - The destination of a message is determined by the
computers IP number and the port number - Every machine has 216 ports
- The origin of the message is also a socket but
most of the times the port number is not
important - Ports are associated to services (programs)
11The 3 basic communication forms
- UDP communication reflects almost what really
happens over the internet. An application sends a
packet trough a socket addressed to a certain IP
number and port. There should be another
application on that host listening to packets
coming to that port (which is agreed beforehand) - TCP simulates a data flow. A client must
establish a communication with the server before
starting sending/receiving data. The server must
be waiting for such request. - Multicast fits well for group communication
when the group is not well defined beforehand
(spontaneous networking). It is also based in the
sending of UDP packages but all interested
applications may receive it. It does not require
a central server
12(No Transcript)
13The SOCKET
When a server wants to start listening it must
create a socket bound to a port. The port is
specified with a number.
www.informatik.de
4444
3333
5555
If a client wants to communicate with server 1
should try to communicate with computer
www.informatik.de through port 4444
14UDP communication with datagrams
DATAGRAM an independent, self-contained message
sent over the internet whose arrival, arrival
time and content are not guaranteed (like regular
mail in some countries....)
Once a server is listening, the client should
create a datagram with the servers address, port
number and, the message
www.informatik.de
www.waseda2.jp
?
4444
www.waseda1.jp
4444
message
15Sending datagrams with UDP protocol
Then it should open a socket and send the
datagram to the internet. The routing algorithm
will find the way to the target computer
www.waseda2.jp
www.informatik.de
?
3333
4444
16Before the datagram leaves the client, it
receives the address of the originating computer
and the socket number
www.waseda2.jp
www.informatik.de
!
3333
4444
17Sending datagrams with UDP protocol
After the datagram is sent, the client computer
may start hearing at the port created for sending
the datagram if an answer from the server is
expected
www.waseda2.jp
www.informatik.de
?
3333
4444
18Sending datagrams with UDP protocol
The server can extract the clients address and
port number to create another datagram with the
answer
www.waseda2.jp
www.informatik.de
?
3333
4444
answer
19Sending datagrams with UDP protocol
Finally is sends the datagram with the answer to
the client. When a datagram is sent there is no
guarantee that it will arrive to the destination.
If you want reliable communication you should
provide a checking mechanism, or use ...
www.waseda2.jp
www.informatik.de
?
3333
4444
20TCP communication with data flow
With TCP a communication channel between both
computers is built and a reliable communication
is established between both computers. This
allows to send a data flow rather tan datagrams.
www.waseda2.jp
www.informatik.de
?
3333
4444
21TCP communication with data flow
After the client contacts the server, a reliable
channel is established. After this, client and
server may begin sending data through this
channel. The other should be reading this data
They need a protocol !!!!
www.waseda2.jp
www.informatik.de
bla
bla
bla
bla
3333
4444
22TCP How is reliability achieved ?
The internet itself works only with the datagram
paradigm. Internet frames are may get lost
(destroyed) For every frame delivered carrying a
part of the data flow there is a confirmation!
Sending bla bla bla
Sending 1st bla
Ack 1st bla
Sending 2nd bla
Ack 2nd bla
Sending 3rd bla
Ack 3rd bla
23What if a message get lost ?
The server waits a certain amount of time. If it
does not receive any confirmation it sends the
message again.
Sending 1st bla
Sending bla bla bla
Ack 1st bla
Sending 2nd bla
LOST !!!
Sending 2nd bla again
No confirmation !!!
Ack 2nd bla
24The Window for improving efficiency
The transmitter will handle a set of not
acknowledged packets
Sending 1st bla
Sending 2nd bla
Sending 3rd bla
Ack 1st bla
Ack 2nd bla
Ack 3rd bla
25(No Transcript)
26(No Transcript)
27Mark with a the applications to use TCP and
with a those to use UDP
Video conference
E-Mail
Web server and client
Stock values every 5 seconds
Temperature every second
28The client-server paradigm(do you remember the
WEB ?)
answer
request
THE INTERNET
answer
request
291- The server opens a channel and starts
listening to requests.
?
1
THE INTERNET
302- A client who knows it, sends a request and
waits for the answer
2
THE INTERNET
2
313- The server, analyses the request and answers
properly according to the protocol
3
THE INTERNET
3
This may involve the reading of a file
32(No Transcript)
33The Client-Server Model
request
answer
34Services Provided by Multiple Servers
35Proxy servers caches
36Peer-to-peer Applications (p2p)
37Communication Architectures for Distributed
Applications
38Network communication architecture
39Star communication architecture
40Replicated Architecutres
41Replicated Architecture
Data
Data
Data
42Semi-replicated Architectures
43Semi-replicated Architecture
Data
Data
Data
44Centralized Architecture
45Full centralized Architecture
view / commands
view / commands
46Nowadays there is a lot of middleware which make
distributed programming much easier
RPC, CORBA, RMI
47Goals of the Middleware
- Provide a framework for making development of
distributed system easier - Hide (encapsulate) communications details
- Make distributing programming similar to local
programming - Standardization of communication protocols and
data format - This help comes not for free !!!
48Web-Based Distributed Systems
- Applications talk to each other using HTTP
protocol - Trough port 80 (usually the only available)
- Thin clients Fat Servers
- Use of Web and Application servers
- The server is extended to implement new
services
49J2EE Basic Architecture
Web Server
Client Web Browser
Database Server
Application Server
HTML Pages Servlets JSP pages
EJB
Communication via JDBC