CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.

Slides:



Advertisements
Similar presentations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
Advertisements

Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
Computer Networks21-1 Chapter 21. Network Layer: Address Mapping, Error Reporting, and Multicasting 21.1 Address Mapping 21.2 ICMP 21.3 IGMP 21.4 ICMPv6.
Universidad de Chile - Tupper 2007, Santiago - Fono: Fax: Módulo 9: Desarrollo de Aplicaciones.
UDP Datagrams and Sockets Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University.
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Universidad de Chile - Tupper 2007, Santiago - Fono: Fax: Módulo 9: Desarrollo de Aplicaciones.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CS 491, 591 Networking in Java Summer Establishing a Simple Server (Using Stream Sockets) Creating a Java server –Create ServerSocket object ServerSocket.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Java Socket Support Presentation by: Lijun Yuan Course Number: cs616.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Client/Server In Java An Introduction to TCP/IP and Sockets.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Projekt współfinansowany przez Unię Europejską w ramach Europejskiego Funduszu Społecznego „Networking”
1 Server-Client communication without connection  When the communication consists of sending and/or receiving datagram packets instead of a data stream.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Server-Client communication without connection When the communication consists of sending and/or receiving datagram packets instead of a data stream it.
Building an ftp client and server using sockets we now know enough to build a sophisticated client/server application!  ftp  telnet  smtp  http.
Babak Esfandiari (based on slides by Qusay Mahmoud)
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
IX. Multicast Sockets.
CS451 - Lecture 4 1 CS451 Lecture 4: Network Programming Yugi Lee STB #555 (816) * Acknowledgement:
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
 Socket  The combination of an IP address and a port number. (RFC 793 original TCP specification)  The name of the Berkeley-derived application programming.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
Fall 2005Computer Networks20-1 Chapter 20. Network Layer Protocols: ARP, IPv4, ICMPv4, IPv6, and ICMPv ARP 20.2 IP 20.3 ICMP 20.4 IPv6.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Lecture 9 Network programming. Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on the Internet.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Lector: Aliyev H.U. Lecture №10 Multicast network software design TASHKENT UNIVERSITY OF INFORMATION TECHNOLOGIES THE DEPARTMENT OF DATA COMMUNICATION.
Java Sockets Programming
UDP User Datagram Protocol. User Datagram Protocol (UDP) UDP is the protocol available to network programmers who wish to send datagrams UDP datagrams.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
From Coulouris, Dollimore, Kindberg and Blair Distributed Systems: Concepts and Design Edition 5, © Addison-Wesley 2012 Slides for Chapter 4: Interprocess.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Introduction to Sockets “A socket is one endpoint of a two-way communication link between two programs running on the network. A socket is bound to a port.
Part 4: Network Applications Client-server interaction, example applications.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
1 IP Multicast G53ACC Chris Greenhalgh School of Computer Science.
Java Programming II Java Network (I) Java Programming II.
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
UDP Programming. Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 2/86 Overview.
CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina.
Network Programming Communication between processes Many approaches:
Socket Programming Ameera Almasoud
Advanced Java Programming Unit One: Networking
Chapter 11 User Datagram Protocol
Block 14 Group Communication (Multicast)
Text extensions to slides © David E. Bakken,
NETWORK PROGRAMMING CNET 441
CPSC 441 UDP Socket Programming
Server-Client communication without connection
Server-Client communication without connection
Socket Programming with UDP
Presentation transcript:

CSCE 515: Computer Network Programming Chin-Tser Huang University of South Carolina

2/19/20042 ICMP Source Quench Error type(4)code(0) checksum IP header + first 8 bytes of original datagram data unused (must be 0)

2/19/20043 Address Bindings of UDP Server Three types of address bindings localIP.lport and foreignIP.fport localIP.lport and *.* *.lport and *.*

2/19/20044 Broadcasting and Multicasting Send message from single source to all or multiple destinations Only apply to UDP (why?) Broadcasting is to send a message to every host on the cable Multicasting is to send a message to a set of hosts that belong to a multicast group

2/19/20045 Broadcasting Four types of IP broadcast addresses Limited broadcast: Net-directed broadcast: e.g. netid for a class A network ID Subnet-directed broadcast: all “1” bits for host ID but need a specific subnet ID All-subnets-directed broadcast: need to know subnet mask

2/19/20046 Multicasting Two types of services Delivery to multiple destinations Solicitation of servers by clients

2/19/20047 Multicast Group Address Combination of high-order 4 bits of “1110” and multicast group ID Range is –

2/19/20048 Host Group Set of hosts listening to a particular IP multicast address Can span multiple networks Membership is dynamic; hosts can join and leave at any time Permanent host groups : all systems on this subnet : all routers on this subnet : Network Time Protocol (NTP) : RIP-2

2/19/20049 Class MulticastSocket Constructors MulticastSocket() MulticastSocket(int port)

2/19/ Class MulticastSocket Methods void joinGroup(InetAddress group) throws IOException void leaveGroup(InetAddress group) throws IOException void setTimeToLive(int ttl) throws IOException void setTTL(byte ttl) throws IOException int getTimeToLive() throws IOException byte getTTL() throws IOException void send(DatagramPacket packet, byte ttl) throws IOException void setInterface(InetAddress address) throws SocketException InetAddress setInterface() throws SocketException

2/19/ Class MulticastSocket Exceptions IOException SecurityException

2/19/ Sending Multicast Packets // byte[] data // InetAddress multicastGroup // int multicastPort MulticastSocket socket = new MulticastSocket(); DatagramPacket packet = new DatagramPacket (data, data.length, multicastGroup, multicastPort); socket.send(packet, (byte) 64); socket.close();

2/19/ Receiving Multicast Packets MulticastSocket socket = new MulticastSocket(multicastPort); Socket.joinGroup(multicastGroup); byte buffer[] = new byte[65508]; DatagramPacket packet = new DatagramPacket(); socket.receive(packet); InetAddress fromAddress = packet.getAddress(); int fromPort = packet.getPort(); int length = packet.getLength(); byte[] data = packet.getData(); // … socket.leaveGroup(multicastGroup); socket.close();

2/19/ A Peer-to-Peer Multicast Chat System Each client multicasts its message to other clients No server is involved; all clients communicate as peers Open a chat frame and start a thread that listens for incoming packets

2/19/ MulticastChat.java /* * Java Network Programming, Second Edition * Merlin Hughes, Michael Shoffner, Derek Hamner * Manning Publications Company; ISBN X * * * * Copyright (c) Merlin Hughes, Michael Shoffner, Derek Hamner; * all rights reserved; see license.txt for details. */ import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; public class MulticastChat implements Runnable, WindowListener, ActionListener { // public MulticastChat (InetAddress group, int port) … // public synchronized void start () throws IOException … // public void windowOpened (WindowEvent event) … // public void windowClosing (WindowEvent event) … // public void actionPerformed (ActionEvent event) … // public void run () … // public static void main (String[] args) throws IOException … }

2/19/ Constructor MulticastChat protected InetAddress group; protected int port; public MulticastChat (InetAddress group, int port) { this.group = group; this.port = port; initAWT (); } // protected void initAWT () …

2/19/ Method initAWT protected Frame frame; protected TextArea output; protected TextField input; protected void initAWT () { frame = new Frame ("MulticastChat [" + group.getHostAddress () + ":" + port + "]"); frame.addWindowListener (this); output = new TextArea (); output.setEditable (false); input = new TextField (); input.addActionListener (this); frame.setLayout (new BorderLayout ()); frame.add (output, "Center"); frame.add (input, "South"); frame.pack (); }

2/19/ Method start protected Thread listener; public synchronized void start () throws IOException { if (listener == null) { initNet (); listener = new Thread (this); listener.start (); frame.setVisible (true); } // protected void initNet () throws IOException …

2/19/ Method initNet protected MulticastSocket socket; protected DatagramPacket outgoing, incoming; protected void initNet () throws IOException { socket = new MulticastSocket (port); socket.setTimeToLive (1); socket.joinGroup (group); outgoing = new DatagramPacket (new byte[1], 1, group, port); incoming = new DatagramPacket (new byte[65508], 65508); }

2/19/ Method stop public synchronized void stop () throws IOException { frame.setVisible (false); if (listener != null) { listener.interrupt (); listener = null; try { socket.leaveGroup (group); } finally { socket.close (); }

2/19/ Window-related Methods public void windowOpened (WindowEvent event) { input.requestFocus (); } public void windowClosing (WindowEvent event) { try { stop (); } catch (IOException ex) { ex.printStackTrace (); } public void windowClosed (WindowEvent event) {} public void windowIconified (WindowEvent event) {} public void windowDeiconified (WindowEvent event) {} public void windowActivated (WindowEvent event) {} public void windowDeactivated (WindowEvent event) {}

2/19/ Method actionPerformed public void actionPerformed (ActionEvent event) { try { byte[] utf = event.getActionCommand ().getBytes ("UTF8"); outgoing.setData (utf); outgoing.setLength (utf.length); socket.send (outgoing); input.setText (""); } catch (IOException ex) { handleIOException (ex); } // protected synchronized void handleIOException (IOException ex) …

2/19/ Method handleIOException protected synchronized void handleIOException (IOException ex) { if (listener != null) { output.append (ex + "\n"); input.setVisible (false); frame.validate (); if (listener != Thread.currentThread ()) listener.interrupt (); listener = null; try { socket.leaveGroup (group); } catch (IOException ignored) { } socket.close (); }

2/19/ Method run public void run () { try { while (!Thread.interrupted ()) { incoming.setLength (incoming.getData ().length); socket.receive (incoming); String message = new String (incoming.getData (), 0, incoming.getLength (), "UTF8"); output.append (message + "\n"); } } catch (IOException ex) { handleIOException (ex); }

2/19/ Method main public static void main (String[] args) throws IOException { if ((args.length != 1) || (args[0].indexOf (":") < 0)) throw new IllegalArgumentException ("Syntax: MulticastChat : "); int idx = args[0].indexOf (":"); InetAddress group = InetAddress.getByName (args[0].substring (0, idx)); int port = Integer.parseInt (args[0].substring (idx + 1)); MulticastChat chat = new MulticastChat (group, port); chat.start (); }

2/19/ Next Class IGMP DNS TCP Read TI Ch. 13, 14, 17 Dr. Zachary will give lecture