Presentation is loading. Please wait.

Presentation is loading. Please wait.

Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Módulo 9: Desarrollo de Aplicaciones.

Similar presentations


Presentation on theme: "Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Módulo 9: Desarrollo de Aplicaciones."— Presentation transcript:

1 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 1 Server-Client communication without connection  When the communication consists of sending and/or receiving datagram packets instead of a data stream it is called a connectionless communication  This means there is no “virtual link” created between both end of a communication.  This is very near to how the packages are actually delivered over the over the internet.  This is why the arriving, order or uniqueness of packages cannot be guaranteed.

2 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 2 Datagram management with JAVA  Communication is based on assembling UDP packages and sending them to the interent. An UDP package consists of:  Data: a bytes array  Destination Port : int  Destination Address: InetAddress  A server start by listening at a certain port for packages.  The client assembles a packages and send it to the net.  The server receives the package (routed by the net to its final destination) and extracts the data.  If the server needs to answer, it extracts the sender address and port (the client must be listening for packages)

3 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 3 UDP: communication with datagrams DATAGRAM: an independent, self-contained message sent over the internet whose arrival, arrival time and content are not guaranteed A SERVER A CLIENT 4444 www.waseda1.jp message 4444 Once a server is listening, the client should create a datagram with the server’s address, port number and, the message www.waseda2.jp ?

4 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 4 Sending 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 A SERVER A CLIENT 4444 www.waseda1.jp 3333 www.waseda2.jp ?

5 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 5 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

6 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 6 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 ?

7 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 7 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 ?

8 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 8 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 ?

9 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 9 Classes for Datagrams in Java: Send  Create a socket for sending a Datagram to the internet  DatagramSocket ds = new DatagramSocket();  Create and assemble the Datagram  byte[] data = new byte[256];  InetAddress address = InetAddress.getByName(“www.ctc.cl”);  DatagramPacket pack = new DatagramPacket(data, data.length,address,4444);  Send  ds.send(pack);  Wait for an answer  socket.receive(pack); //make sure it is clean before, perhaps by using a new one !!! EchoUDP & EchoUDP2

10 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 10  Start listening for Datagrams on a certain socket  socket = new DatagramSocket(4444);  Preparing a Datagram for receiving data  byte[] data = new byte[256];  DatagramPacket pack = new DatagramPacket(data,data.length);  Start listening for a package  socket.receive(pack);  Obtaining the data and address and port of sender  int port = pack.getPort();  InetAddress address = pack getAddress();  String content = new String(pack.getData());  Or just by using the data variable which points to the byte-array Classes for Datagrams in Java: Receive Tiro/ReciboPaquetes

11 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 11 The Remote Clock A remote clock server will provide the client with the actual time Remote clock server UDPClockClient UDPClockServer

12 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 12 A Multithreded Clock Server UDPClockServerThread UDPCLockMServer

13 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 13 What about package loss ?  UDP Packages can get lost like internet packages  We can trace this by numbering the packages  Let´s do following experiments:  Trace package loss between Chile and Germany  Trace package loss between Japan and Chile  Trace package loss between Chile and Japan  For the local network:  Trace package loss with variable number of clients-servers Tiro/ReciboPaquetesNoEnd

14 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 14 An UDP Ping Client  We will use the echo server by default  In a unix machine there is normally an echo server listening at port 7 for UDP and for TCP requests  It is not the same server, but it is possible to open 2 sever sockets for the same port but for different protocols  The Ping client will send a package to the server with time of issue, which will be returned by the server  By comparing time in the Datagram and current time we can have the round-trip delay  The program will also calculate max/min and avg Ping.java

15 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 15 Multicasting & Broadcasting  If a server must distribute information to many clients it may overload its resources  This is especially true in situations like videoconferencing (multipoint), where several frames per seconds should be transmitted to may be several clients: this is not possible in the practice!  In multicasting and broadcasting the server transmits this information only once.  This requires the hardware (network) to support this

16 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 16 Multicast & Broadcast  Multicast & Broadcast are protocols which allow an application to put a single package on the net which will be received by many other applications,  Broadcast works only inside a local network. A “broadcasted” package will be received by all.  It requires support from the local network.  Multicast will arrive only to “interested” clients which have registered before  Multicast requires host and routers to support the IGMP routing algorithm

17 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 17 Multicast  Multicast in Java is similar to UDP except that sending-receiving should be implemented on an IP number in the range between (224.0.0.0 - 239.255.255.255)  In order to receive the Multicast packs the client must express interest in joining a certain multicast group at a certain multicast address and port. The network, (the routers) will deliver the packs to the interested hosts  Any application can transmit packs to the group !

18 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 18 Multicast  The packet will be picked up my any machines on the local network that are interested in that group.  In addition it will be picked up by routers that will forward it as appropriate to adjacent networks that are interested The significant complexity of multicast is how routers will know what adjacent networks are interested This requires the storage of additional information in the routing table

19 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 19 Time to Live  Multicast packets include a TTL field that limits the propagation across the internet  In general, every time a packet is relayed by a router or a tunnel the value of TTL will be decreased  When it reaches cero the package is discarded  This concept is also present on every internet packet !

20 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 20 Java Support for Multicast  MulticastSocket: extension of DatagramSocket  MulticastSocket( ) bounds it to any available port  MulticastSocket(int port) bounds it to a specific port  Many multicast socekts can be bound to the same port! (contrary to TCP or UDP sockets)  Methods are inherited (send, receive) + 3 new  joinGroup(InetAddress group)  leaveGroup(InetAddress group)  setTimeToLive(int ttl) MulricastServer/client

21 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 21 A Multicast Based Chat  There is no server.  Each participant runs the exactly same program, joining a common Multicast group The messages are “multicasted” over the net, thus everyone joining the group will receive them There is no guarantee about the arriving, arriving time, or duplication of messages MulricastChat

22 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 22 MBone  Multicast is currently not widely deployed on the Internet so it is not possible to implement it across different networks. This is mainly because of the routers not supporting the IGMP  There is a subnet called MBone which communicate multicast-enabled islands, allowing the transport of multicast packets through tunnels.  A tunnel communicates the routers of two networks which are not physically adjacent.  Packages will be forwarded from router to the other as if there were actually neighboring networks

23 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 23 Broadcast  Broadcast is similar a Multicast but in a local network  Every Broadcast based network (like ethernet) has a broadcast IP address. Any message sent to this address will be received by all computers on the local network  Usually this is the last IP address of the subnet:  Clase C: 192.1.2.0 -> 192.1.2.255  Para una subred de 16 hosts 197.84.66.192 -> 197.84.66.207  A port number should be agreed UDPBroadcastClient/Server

24 Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Email: victoria.gaete @die.uchile.cl2000/1 Módulo 9: Desarrollo de Aplicaciones en Redes de Computadores 24 ¿ Broadcast or Multicast ?  If you can chose it is better to use Multicast because it does not disturb other machines  Sometimes is necessary to have privileges to write on a broadcast address.  Multicast allows many multicast groups in the same network  The generated traffic is the same: one package which is received by all members  Broadcast works in Java like common UDP. Only the IP address is special


Download ppt "Universidad de Chile - Tupper 2007, Santiago - Fono: 678 4888 - Fax: 698 8427 - Módulo 9: Desarrollo de Aplicaciones."

Similar presentations


Ads by Google