the inetaddress class a class for storing and managing internet addresses (both as ip numbers and as...
TRANSCRIPT
The InetAddress Class
• A class for storing and managing internet addresses (both as IP numbers and as names).
• The are no constructors but “class factory” – InetAddress n = InetAddress.getLocalHost()– InetAddress n = InetAddress.getByName(nombre)
• The most important methods: – String nombre = n.getHostName()– String direccion = n.getHostAddress()
• See the example InetExample.java & Names.java
Why distributed systems
- Share resources- Communicate people- Performance, scalability- Fault tolerant systems
We know already how computers communicate but...
... how do programs communicate?
PROG1 PROG2
They need to establish a protocol !
- Who send the data first- What kind of data- How to react to the data
Every layer has the illusion of talking to the same one located at the other host
A SERVER
A CLIENT
A CLIENT
A CLIENT
4444
The UDP: User Defined Package: like writing a letterRead write sequence
UDP or TCP communication
Internet frames and addresses
electricpulses
Decisions when Developing a Distributed System
• Which service from the transport layer are we going to use (TCP, UDP, or a middleware)
• Software architecture: replicated, centralized• Communications architecture: centralized,
networked• Server design: concurrent, iterative, stateless, with
state• Etc…
Internet : two different ways to deliver a message to another application
The UDP: User Defined Package: like writing a letter
TCP or UDP
Applications’ programmers decide on this according to their needs
Nowadays there is a lot of middleware which make distributed programming
much easier
Libraries for distributedprogramming (middleware)
RPC, CORBA, RMI
The client-server paradigm(do you remember the WEB ?)
The web server program
Webresources
request
answer
THE INTERNET
requestanswer
The web client program
1- The server opens a channel and starts listening to requests.
A SERVER
Webresources
THE INTERNET
A CLIENT
1 ?
2- A client who knows it, sends a request and waits for the answer
A SERVER
Webresources
THE INTERNET
A CLIENT
2
2
3- The server, analyses the request and answers properly according to the
protocol
A SERVER
Webresources
THE INTERNET
A CLIENT
3
3
This may involve the reading of a file
Why Client/Server ? It is a communication protocol model (listener/caller)
• TCP/IP does not provide any mechanism which would start running a program in a computer when a message arrives. A program must be executing BEFORE the message arrives in order to establish a communication (daemons).
• Is there really no other mean to communicate ?– Multicasting (but the sender does not know who is receiving and
in this case there is no dialogue)
• What are the protocol ports of a server machine ?– It is a virtual address inside the machine at a server listening to
client requirements asking for a certain service. In most Unix machines there are “well known ports” which are associated to a server program providing a service trough a protocol. Port number and protocol should be well known.
Protocols for Communication• Parameterized client applications
– Generalizing the application scope. For example: Unix telnet can be used for requesting other services: try telnet host 7, telnet host 13 y telnet host 80)
• When designing client applications include parameters to fully specify machine and port to which the application should communicate trough its implemented protocol.
• Servers with or without Connection– The modalities connectionless style and connection-oriented style
depend on the protocol type we use for connecting to a certain machine. In the TCP/IP world we have the TCP (connection oriented) and UDP (without connection) protocols
TCP or UDP Protocol: decision at the transport level
• What does it means for the programmer/designer: – By choosing one or the other protocol for establishing a connection
between machines the programmer/designer decides about the reliability and speed of the communication.
• TCP provides high reliability: data are only sent if the communication was established. An underlying protocol is responsible for retranslating, ordering, eliminating duplicate packages
• UDP reflects just what the internet does with the packages: best effort delivery, no checking.
– Also the programming style is quite different : • With TCP the data is sent a flow (of bytes, in principle) which can be
written, read as if they were stored in a file.
• With UDP the programmer must assemble the package and send it to the internet without knowing if it will arrive its pretended destination
When to use one or another
• Considerations – TCP imposes a much higher load to the network than UDP (almost 6
times)
– We can expect high package loss when the information travels trough many routers.
– Inside a LAN UDP communications may be reliable is there is not much traffic. Although with some congestion we can expect some packages to be lost inside the LAN
• In general, it is recommended especially for beginners (but also to skilled programmers) to use only TCP to develop distributed applications. Not only it is more reliable but the programming style is also simpler. UDP is normally used if the application needs to implement hardware supported broadcasting or multicasting, or if the application cannot tolerate the overload of TCP
The channel which server and client use to communicate (either int TCP or
UDP) is called SOCKET
A SERVER 1
When a server wants to start listening it must create a socketbound to a port. The port is specified with a number.
A SERVER 2
A SERVER 3
www.thisserver.jp
4444
3333
5555
If a client wants to communicate with server 1 should try to communicate with computer www.thisserver.jp through port 4444
UDP: communication with datagramsDATAGRAM: an independent, self-contained message sent over the internet whose arrival, arrival time and content are not guaranteed (like regular mail in some countries....)
A SERVER A CLIENT
4444
www.waseda1.jp
www.waseda1.jp
message
4444
Once a server is listening, the client should create a datagramwith the server’s address, port number and, the message
www.waseda2.jp
?
Sending datagrams with UDP protocol
Then it should open a socket and send the datagramto the internet. The “routing algorithm” will find the way to the target computer
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
?
Before the datagram leaves the client, it receives the address of the originating computer and the socket number
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
!
Sending datagrams with UDP protocol
Sending 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
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
?
Sending datagrams with UDP protocol
The server can extract the client’s address and port number to create another datagram with the answer
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
answer
?
Sending 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 ...
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
?
TCP: 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.
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
?
TCP: 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 !!!!
A SERVER A CLIENT
4444
www.waseda1.jp
3333
www.waseda2.jp
bla bla bla bla
TCP: 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
What 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 bla bla bla
Sending 1st bla
Ack 1st bla
Sending 2nd bla
Sending 2nd bla again
Ack 2nd bla
No confirmation !!!
LOST !!!
The Window for improving efficiencyThe transmitter will handle a set of not acknowledged packets
Sending 1st bla
Ack 1st bla
Sending 2nd bla
Ack 2nd bla
Sending 3rd bla
Ack 3rd bla
When do programmers should use UDP or TCP ?
- TCP generates 6 times more traffic than UDP- It is also slower to send and receive the messages
- Reliable- Complete
- Valid in a certainperiod of time
- No need of speed
UDP TCP
- not complete info- fast- valid in a very short period of time- history not important
Mark with a + the applications to use TCP and with a = those to use UDP
E-Mail Video conference
Temperature every second
Web server and client
Stock values every 5 seconds