Relaying Datagrams
Following the idea of the TCP relay, a UDP datagram relay receives datagrams on a particular port number and resends them to another address and port.
Listing 31.3 shows a simple datagram relay.
Code Listing 31.3. Source Code for DatagramRelay.java
package usingj2ee.net; import java.net.*; import java.io.*; public class DatagramRelay { public static void main(String[] args) { if (args.length < 3) { System.out.println("Please supply a local port, a remote host "+ " and a remote port."); System.exit(0); } int localPort = 0; try { localPort = Integer.parseInt(args[0]); } catch (Exception exc) { System.out.println("Invalid local port: "+args[0]); System.exit(0); } int remotePort = 0; try { remotePort = Integer.parseInt(args[2]); ... |
Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.