Outline of Topics. UDP Socket Java Programming. Multicast in Java. Real-time protocol (RTP) XMPP and Jingle protocols. Java I/O and New IO (NIO)

Similar documents
Construction d Applications Réparties / Master MIAGE

Joseph Faber Wonderful Talking Machine (1845)

Distributed Programming in Java

JAVA Network API. 2 - Connection-Oriented vs. Connectionless Communication

Interprocess Communication

Introduction to NIO: New I/O

CSCD 330 Network Programming Spring 2018

4. The transport layer

Communication Paradigms

CSCD 330 Network Programming Winter 2019

JAVA SOCKET PROGRAMMING

CS 4390 Computer Networks. Transport Services and Protocols

Networking. Lecture 25 ish? COP 3252 Summer July 11, 2017

Lecture 3: Socket Programming

Transport Layer Overview

Introduction to the Application Layer. Computer Networks Term B14

C19: User Datagram and Multicast

Internet Group Communication: IP Multicasting

C18: Network Fundamentals and Reliable Sockets

CSC 4900 Computer Networks: P2P and Sockets

OSI Transport Layer. Network Fundamentals Chapter 4. Version Cisco Systems, Inc. All rights reserved. Cisco Public 1

Chapter 9: UDP sockets & address conversion function

The ASP Virtual Networking (VNET) Component. 23 July Abstract

Transport Over IP. CSCI 690 Michael Hutt New York Institute of Technology

4 rd class Department of Network College of IT- University of Babylon

Networking: IPv6, UDP and TCP. Network Programming in Java UDP and TCP

Chapter 2: outline. 2.1 principles of network applications. 2.6 P2P applications 2.7 socket programming with UDP and TCP

Effec%ve So*ware. Lecture 6: Non-blocking I/O, C10K, efficient networking. David Šišlák

Client/Server Computing & Socket Programming

31 Network Programming

Outlines. Networking in Java. Internet hardware structure. Networking Diagram. IP Address. Networking in Java. Networking basics

Communication in Distributed Systems: Sockets Programming. Operating Systems

Ch.11 Nonblocking I/O

CN1047 INTRODUCTION TO COMPUTER NETWORKING CHAPTER 6 OSI MODEL TRANSPORT LAYER

Lecture 3: The Transport Layer: UDP and TCP

Transport protocols Introduction

CSE 461 Module 10. Introduction to the Transport Layer

Da t e: August 2 0 th a t 9: :00 SOLUTIONS

ETSF10 Internet Protocols Transport Layer Protocols

Chapter 5.6 Network and Multiplayer

Introduction to Sockets 9/25/14

Chapter 3 Transport Layer

Internet Protocol (IP) TCP versus UDP

Lecture 2 Communication services The Trasport Layer. Antonio Cianfrani DIET Department Networking Group netlab.uniroma1.it

Chapter 2 Application Layer

Basic Java Network Programming. CS211 July 30 th, 2001

Become a WebRTC School Qualified Integrator (WSQI ) supported by the Telecommunications Industry Association (TIA)

Chapter 2. Application Layer. Chapter 2: Application Layer. Application layer - Overview. Some network apps. Creating a network appication

Advanced Java Programming. Networking

Internet Group Communication: IP Multicasting

Transport Layer. <protocol, local-addr,local-port,foreign-addr,foreign-port> ϒ Client uses ephemeral ports /10 Joseph Cordina 2005

CSC 4900 Computer Networks: Transport Layer

Chapter 3 Transport Layer

UNIT IV -- TRANSPORT LAYER

Transport Layer. Chapter 3: Transport Layer

416 Distributed Systems. Networks review; Day 2 of 2 Fate sharing, e2e principle And start of RPC Jan 10, 2018

Higher layer protocols

CS 3516: Advanced Computer Networks

CMPE 150/L : Introduction to Computer Networks. Chen Qian Computer Engineering UCSC Baskin Engineering Lecture 4

Chapter 2 outline. 2.1 Principles of app layer protocols

Development of reliable protocol Sliding window protocols. C = channel capacity in bps I = interrupt/service time + propagation delay

Improving Java Network Programming. Brian Runk, 25 Apr 2006

Lecture 4: The Transport Layer and UDP

Chapter II: Application Layer

Multimedia! 23/03/18. Part 3: Lecture 3! Content and multimedia! Internet traffic!

Part 3: Lecture 3! Content and multimedia!

Multimedia Networking

OSI Transport Layer. objectives

The TCP Protocol Stack

This is a sample chapter of WebRTC: APIs and RTCWEB Protocols of the HTML5 Real-Time Web by Alan B. Johnston and Daniel C. Burnett.

CCNA 1 Chapter 7 v5.0 Exam Answers 2013

Different Layers Lecture 20

UDP and TCP. Introduction. So far we have studied some data link layer protocols such as PPP which are responsible for getting data

Overview. Communication types and role of Middleware Remote Procedure Call (RPC) Message Oriented Communication Multicasting 2/36

Transport layer protocols. Lecture 15: Operating Systems and Networks Behzad Bordbar

TCP and Concurrency. The third assignment at DA

Lecture 11. Transport Layer (cont d) Transport Layer 1

Interprocess Communication

CSE 461 Module 11. Connections

Networking Technologies and Applications

CSC 401 Data and Computer Communications Networks

CSCD 330 Network Programming

Master Course Computer Networks IN2097

ECE 435 Network Engineering Lecture 15

CPSC 441 Tutorial - 11 UDP Socket Programming Department of Computer Science University of Calgary

Java Socket Workshop. July Purpose of this workshop:

CS UDP: User Datagram Protocol, Other Transports, Sockets. congestion worse);


CMPE 80N: Introduction to Networking and the Internet

Transporting Voice by Using IP

Input ports, switching fabric, output ports Switching via memory, bus, crossbar Queueing, head-of-line blocking

Reading and Writing Files

Chapter 2 Applications and

RTP. Prof. C. Noronha RTP. Real-Time Transport Protocol RFC 1889

Introduction to Network Programming using Java

Chapter 3: Transport Layer Part A

What is a Network? TCP / IP. The ISO OSI Model. Protocols. The TCP/IP Protocol Suite. The TCP/IP Protocol Suite. Computer network.

The aim of this unit is to review the main concepts related to TCP and UDP transport protocols, as well as application protocols. These concepts are

CPSC 441 UDP Socket Programming. Department of Computer Science University of Calgary

Operating Systems. 16. Networking. Paul Krzyzanowski. Rutgers University. Spring /6/ Paul Krzyzanowski

Transcription:

Outline Outline of Topics UDP Socket Java Programming Multicast in Java Real-time protocol (RTP) XMPP and Jingle protocols Java I/O and New IO (NIO)

UDP Socket Java Programming User Datagram Protocol (UDP) Sends independent packets of data (called datagrams) between computers without guarantees about arrival and sequencing. Transaction-oriented: suitable for simple query-response protocols Not connection-based (point-to-point) like TCP: suitable for very large numbers of clients Lack of retransmission delays

UDP Socket Java Programming Datagrams Datagrams: an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed. UDP header consists of 4 fields, each of which is 16 bits Table : UDB datagram Bit 0-15 16-35 0 Source port Destination port 32 Length Checksum... Data

UDP Socket Java Programming Datagrams: checksum Used for error-checking of the UDP header and data Also include IP address to prevent misrouting Basic idea: the complement of a 16-bit one s complement sum calculated over an IP pseudo-header and the actual UDP data. A pseudo-header: the IP header and the UDP header without checksum field At the receiver end: all the 16-bit words of the headers plus data area are added together = Sum Sum + Checksum = 11111111 11111111

UDP Socket Java Programming Datagrams: checksum calculation Source IP address UDP total length Protocol Destination IP address Source port number Data Destination port number

UDP Socket Java Programming UDP datagram communication in Java Two packages in java.net package: DatagramPacket : contains several constructors for creating datagram packet object Example: DatagramPacket(byte[] buf, int length, InetAddress address, int port); DatagramSocket : provides various methods for transmitting or receiving datagrams over the network Example: void send(datagrampacket p) or void receive(datagrampacket p)

UDP Socket Java Programming Example 1: UDP word counting server We will create a simple UDP server waits for clients requests and then accepts the message (datagram) and send back the number of words in the message.

Multicast in Java Multicast Imaging you need to send message to a group of 1,000 clients What s wrong with TCP? Connection-based: you need 1,000 connections which consume a lot of processing power on sender! Flow control: The arrival time is not the same for every clients Multicast is a special feature of UDP protocol that enable programmer to send message to a group of receivers on a specific multicast IP address and port. One-to-many and many-to-many real-time communication over internet Send data only once to any number of any receivers

Multicast in Java Multicast: Java example A multicast group is specified by a class D IP address and by a standard UDP port number. Class D IP addresses are in the range 224.0.0.0 to 239.255.255.255, inclusive. Receivers must join multicast group to receive packet Multicast IP address Sender Joint to receive multicast message Receivers

Multicast in Java Multicast: Java example MulticastSocket class: sending and receiving IP multicast packets A MulticastSocket is a (UDP) DatagramSocket, with additional capabilities for joining groups of other multicast hosts on the internet. For Android App development, you can also use MulticastSocket class

Multicast in Java Multicast: Java example Steps of using MulticastSocket to receive messages Step 1: creating a MulticastSocket with the desired port Step 2: joinng a group using the joingroup(inetaddress groupaddr) Step 3: leaving the group using leavegroup(inetaddress addr) method. method

Multicast in Java Multicast: Java example Steps of using MulticastSocket to send messages Step 1: creating a MulticastSocket Step 2: create a DatagramPacket for a message Step 3: set Time-To-Live (TTL) using Step 4: send data Step 4: close the MulticastSocket settimetolive Note: Time-To-Live (TTL): a value between zero and 255. Every time a router forwards the packet, it decrements the TTL field in the packet header. The packet will dropped if the value reaches zero. Used to avoid packages being looped forever due to routing errors.

Real-time protocol (RTP) Real-time protocol (RTP): What is it? Defined by RFC-1889, RTP, a Transport Protocol for Realtime Applications A standardized packet format for delivering audio and video over IP networks Why: to cope with misordered or lost packets How: ignoring the loss or re-sending the missing data, and processing out-of-order packages Implementations are built on the UDP Allows data transfer to multiple destinations through multicast

Real-time protocol (RTP) Applications of RTP IP Phone Audio conference Video conference IP television / video on demand

Real-time protocol (RTP) Java Media Framework (JMF) A Java library that enables audio, video and other time-based media to be added to Java applications and applets. Used for capturing, playing, streaming, and transcoding multiple media formats Provides support for RTP to enable the transmission and reception of real-time media streams across the network. Cannot be used for Android and lack of updates and maintenance (last update in 2008!) A few alternatives exist, the most promising one is Freedom for Media in Java (FMJ)

Real-time protocol (RTP) Further reading Since JMF and RTP are beyond this module, you can learn from: IBM JMF Tutorial JMF tutorial from Univ. of Colorado Some code examples from Old Dominion University Documents for developing RTP APPs in Android

XMPP and Jingle protocols XMPP: what is it? XMPP: Extensible Messaging and Presence Protocol A open standard communications protocol for message-oriented middleware based on XML Was a open-source project called Jabber Formalize by Internet Engineering Task Force (IETF) as a open standard, no royalties are required Cisco acquired Jabber (Cisco Jabber) in 2008 for Enterprise Instant Messaging Can be used for instant messaging, VoIP, video, file transfer, gaming Used by Google Talk, Facebook s chat, Skype and Microsoft Messenger service. Click Full list or here

XMPP and Jingle protocols Jingle: what is it? An extension to XMPP which adds peer-to-peer (P2P) session control (signaling) for multimedia interactions, e.g., Voice over IP (VoIP) or video conferencing communications. Designed by Google and the XMPP Standards Foundation Real-time Transport Protocol (RTP) as the media transport Google App Engine provides support for Jingle or XMPP You can use the libjingle to develop Google Talk applications Google replaced GTalk with Handouts, as well as their Jingle protocol You can also use this Java library: Smack For Android, you can use asmack Other libraries

XMPP and Jingle protocols Samck Java example: chat with Google Talk We can use Smack to send/receive chat messages to/from Google Talk. You can try Facebook Chat Not in the campus because of the firewall A few tutorials/examples to get you started: Smack official document. A facebook chat client using Smack You can do a lot of cool things: voice chat, video chat, file transfer, games, etc.

Java I/O and New IO (NIO) Java I/O: what is it? I/O: input/output, refers to the interface between a computer/the world, or program/the rest of the computer. Usually built into the operating system. Uses stream metaphor: packaged and transmitted data as one byte at a time, through an object called a Stream. Reminder: Socket is a kind of I/O. Advantages: easy to process the streamed data through I/O, e.g., to create filters. Disadvantages: slow

Java I/O and New IO (NIO) Java NIO: what is it? An alternative Java IO API to the standard Java IO API Offer features for intensive I/O operations Uses a different metaphor: block I/O Block I/O: data is packaged and transmitted in blocks. Advantages: faster than standard stream-oriented I/O You can read more from Oracle s Java page Java 7 release NIO version 2 in 2011: provides extended capabilities for file system tasks,

Java I/O and New IO (NIO) Java NIO: imprtant concepts Two central concept: Channel Buffer Channels are analogous to streams in the original I/O package where you can read and write data. A Buffer is a container object, which holds some data, that is to be written to or that has just been read from. Buffer is the most significant difference between tradition stream-oriented IO and NIO In stream-oriented I/O data is directly written to, and read data from, Stream objects, but in NIO, data is read and write via Buffer

Java I/O and New IO (NIO) Java NIO: Channels details All IO in NIO starts with a Channel. Three types of network related channels: DatagramChannel: read/write data via UDP SocketChannel: read/write data via TCP. ServerSocketChannel: similar to ServerSocket to listen for incoming TCP connections Also file channel: FileChannel Similar to Streams

Java I/O and New IO (NIO) Java NIO: Differences between Channels and Streams Channels are bi-directional: you can both read and write data from/to a Channels. Streams are one-way: you need to use InputStream and OutputStream Channels can be asynchronous, that is, reading and writing data without blocking Channels always read/write data to/from a Buffer.

Java I/O and New IO (NIO) Java NIO: Buffer details Essentially a block of memory, or more precisely, an array. But more than an array: provides structured access to data and also keeps track of the system s read/write processes There are different kinds of Buffer : ByteBuffer: most common one, can be used for most of the I/O operations CharBuffer, ShortBuffer, IntBuffer, LongBuffer, FloatBuffer, DoubleBuffer

Java I/O and New IO (NIO) Java NIO: How to use Buffer? Five steps: Step 1: Create a buffer ByteBuffer buffer = ByteBuffer.allocate(1024); Step 2: Write data from Channel into the Buffer inchannel.read(buffer); Step 3: Call buffer.flip() to switch the buffer from writing mode into reading mode Step 4: Read data out of the Buffer buffer.get() or buffer.array() Step 5: Call buffer.clear() or buffer.compact() to clear the buffer. clear() clears all buffer, compact() only clears the data which you have already read

Java I/O and New IO (NIO) Java NIO: Using FileChannel to read a file. Three steps: Step 1: Get a FileChannel from a FileInputStream Step 2: Create a buffer Step 3: Read from the channel into the buffer Q: How it differs from original I/O? A: Original I/O only creates a FileInputStream and read from that Some tricks to make it even faster: use Channel to Channel Transfers

Java I/O and New IO (NIO) Java NIO network programming: SocketChannel Steps for setting up SocketChannel Step 1: Open a SocketChannel SocketChannel socketchannel = SocketChannel.open(); Step 2: Connect to a server socketchannel.connect (new InetSocketAddress("google.com", 80)); Step 3: Reading/writing from/to a SocketChannel to Buffer Step 4: Close the SocketChannel

Java I/O and New IO (NIO) Java NIO network programming: ServerSocketChannel Steps for setting up ServerSocketChannel Step 1: Open a ServerSocketChannel ServerSocketChannel serversocketchannel = ServerSocketChannel.open(); Step 2: Listening for Incoming Connections while(true) { SocketChannel socketchannel = serversocketchannel.accept(); //communication using socketchannel } Step 4: Close the ServerSocketChannel serversocketchannel.close();

Java I/O and New IO (NIO) Further readings Oracle s tutorial KryoNet : API for efficient TCP and UDP client/server network communication using NIO Five ways to maximize Java NIO and NIO.2 You can ignore those bits on non-blocking or asynchronous mode and selection. I will come back to this after multi-threading programming.