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 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 !!! EchoUDPClient DateUDPClient

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  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 DateUDPServer EchoUDPServer

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

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

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

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

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

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

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

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

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 Spontaneous Networking  Multicasting is the right way to program systems when the participants in the session may come and go very frecuently  This is the case of spontaneous networking with mobile devices in a room  Someone “announce” her precence to the other members by sending message to all at regular intervals  The fact that someone has left is recorded by the others when there have been no messages from her since a certain period of time MulticastRegister

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

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

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