Establishing a Datagram Communication Link

This section describes how to establish a datagram communication link. A server application runs a datagram socket in listen mode and a client application connects a client socket to the server socket.

To establish a datagram communication link, one application program must act as a receiver, create a datagram socket with a given local port number, and set the datagram socket in the receiving mode waiting for a datagram to arrive.

With receiver program running and waiting for a datagram to arrive, the other program can now act as a sender, create a datagram socket with a given local port number, prepare a datagram with the remote address and port number in in, and send it over.

J2SDK offers two main classes to support datagram communication:

1. with methods:

2. representing the datagram with methods:

The following diagram shows steps involved in sending a datagram from one program to another program using the methods provided by DatagramSocket and DatagramPacket classes:

       Sender Program              Receiver Program
       Internet Address #a         Internet Address #b
Step   Available Port #p           Available Port #q
----   -------------------         -------------------
1                                  ds = new DatagramSocket(#b+#q)
2                                  dp = new DatagramPacket()
3                                  ds.receive(dp)
4      ds = new DatagramSocket()   (waiting)
5      dp = new DataPacket()       (waiting)
6      dp.setAddress()             (waiting)
7      dp.setPort()                (waiting)
8      dp.setData()                (waiting)
9      ds.send(dp)                 (receiving datagram)
10                                 (dp is ready)

Table of Contents

 About This JDK Tutorial Book

 JDK (Java Development Kit)

 Java Date-Time API

 Date, Time and Calendar Classes

 Date and Time Object and String Conversion

 Number Object and Numeric String Conversion

 Locales, Localization Methods and Resource Bundles

 Calling and Importing Classes Defined in Unnamed Packages

 HashSet, Vector, HashMap and Collection Classes

 Character Set Encoding Classes and Methods

 Character Set Encoding Maps

 Encoding Conversion Programs for Encoded Text Files

 Java Logging

 Socket Network Communication

Datagram Network Communication

 What Is a Datagram?

Establishing a Datagram Communication Link - A Datagram Server Application - A Datagram Client Application

 DOM (Document Object Model) - API for XML Files

 SAX (Simple API for XML)

 DTD (Document Type Definition) - XML Validation

 XSD (XML Schema Definition) - XML Validation

 XSL (Extensible Stylesheet Language)

 Message Digest Algorithm Implementations in JDK

 Private key and Public Key Pair Generation

 PKCS#8/X.509 Private/Public Encoding Standards

 Digital Signature Algorithm and Sample Program

 "keytool" Commands and "keystore" Files

 KeyStore and Certificate Classes

 Secret Key Generation and Management

 Cipher - Encryption and Decryption

 The SSL (Secure Socket Layer) Protocol

 SSL Socket Communication Testing Programs

 SSL Client Authentication

 HTTPS (Hypertext Transfer Protocol Secure)

 Outdated Tutorials


 Full Version in PDF/EPUB