Sending Data to a Port in UDP Format
The ByteBuffer Class (from the java.nio package) helps you to write data in UDP by converting them to the respective bytes they generally occupy. This is especially helpful when trying to control network traffic.
T
Tutorial Details:
The Code:
import java.net.*;
import java.io.*;
import java.nio.*;
// Initializing the variables
int configRackID = 12;
int configPortID = 760;
//populating the configDataBuffer with the required values.
//Will populate the first 4 bytes
configDataBuffer.putInt(configRackID);
//Will populate the second 4 bytes
configDataBuffer.putInt(configPortID);
// and so on...
//Two ways of creating a datagramSocket. Can use the one required
//Will create a DatagramSocket on port 10000
datagramSocket = new DatagramSocket(10000);
//Will create a DatagramSocket on any available port
datagramSocket = new DatagramSocket();
//Will connect to the IPAddress provided by the serverIP and to the
port specified by listeningPort
Sending Data to a Port in UDP Format
Sending Data to a Port in UDP Format
The ByteBuffer Class (from the java.nio package) helps you to write data in UDP by converting them to the respective bytes they generally occupy. This is especially helpful when trying to control network traffic.
T
XML DOM-lite parser and writer
Summary
This article provides a simple method for creating valid XML and a simple DOM-like (Document Object Model) parser. This method is useful for small applications that need simple XML functionality without the size and complexity of the full range d