com.act365.net
Class SocketUtils

java.lang.Object
  |
  +--com.act365.net.SocketUtils

public class SocketUtils
extends java.lang.Object

SocketUtils provides various utility functions e.g. checksum calculations, functions to read and write numbers from bytestreams and a bytestream dump printer.


Constructor Summary
SocketUtils()
           
 
Method Summary
static short checksum(byte[] source, byte[] destination, byte protocol, short length, byte[] message, int offset)
          Specific checksum calculation used for the UDP and TCP pseudo-header.
static short checksum(byte[] message, int length, int offset)
          Standard internet checksum algorithm shared by IP, ICMP, UDP and TCP.
static void dump(java.io.PrintStream printer, byte[] buffer, int offset, int count)
          Dumps a buffer in printable form.
static int getProtocol()
          Returns the protocol associated with the current DatagramSocketImpl.
static boolean includeHeader()
          Indicates whether the chosen protocol requires the user to include the IP header.
static int intFromBytes(byte[] buffer, int offset)
          Converts consecutive bytes from a buffer into an int.
static void intToBytes(int value, byte[] buffer, int offset)
          Writes an int into a buffer.
static long longFromBytes(byte[] buffer, int offset)
          Converts consecutive bytes from a buffer into a long.
static void longToBytes(long value, byte[] buffer, int offset)
          Writes a long into a buffer.
static void setProtocol(java.lang.String protocollabel)
          Sets the DatagramSocket factory to be used in the program.
static short shortFromBytes(byte[] buffer, int offset)
          Converts consecutive bytes from a buffer into a short.
static void shortToBytes(short value, byte[] buffer, int offset)
          Writes a short into a buffer.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketUtils

public SocketUtils()
Method Detail

setProtocol

public static void setProtocol(java.lang.String protocollabel)
                        throws java.io.IOException
Sets the DatagramSocket factory to be used in the program. The TCP, TCP/J, UDP and ICMP protocols are supported. TCP/J is a clone of TCP that uses the IP protocol code 152. The addition of the Raw prefix to the protocol name indicates that the user wishes to write his own IP headers for the socket. (The option is not supported on Windows). The Socket and ServerSocket factory objects will be set for TCP-based protocols.
Parameters:
protocol - protocol to be used by DatagramSocket objects in the app

getProtocol

public static int getProtocol()
Returns the protocol associated with the current DatagramSocketImpl.

includeHeader

public static boolean includeHeader()
Indicates whether the chosen protocol requires the user to include the IP header.

checksum

public static short checksum(byte[] message,
                             int length,
                             int offset)
Standard internet checksum algorithm shared by IP, ICMP, UDP and TCP.

checksum

public static short checksum(byte[] source,
                             byte[] destination,
                             byte protocol,
                             short length,
                             byte[] message,
                             int offset)
Specific checksum calculation used for the UDP and TCP pseudo-header.

shortFromBytes

public static short shortFromBytes(byte[] buffer,
                                   int offset)
Converts consecutive bytes from a buffer into a short.

intFromBytes

public static int intFromBytes(byte[] buffer,
                               int offset)
Converts consecutive bytes from a buffer into an int.

longFromBytes

public static long longFromBytes(byte[] buffer,
                                 int offset)
Converts consecutive bytes from a buffer into a long.

longToBytes

public static void longToBytes(long value,
                               byte[] buffer,
                               int offset)
Writes a long into a buffer.

intToBytes

public static void intToBytes(int value,
                              byte[] buffer,
                              int offset)
Writes an int into a buffer.

shortToBytes

public static void shortToBytes(short value,
                                byte[] buffer,
                                int offset)
Writes a short into a buffer.

dump

public static void dump(java.io.PrintStream printer,
                        byte[] buffer,
                        int offset,
                        int count)
Dumps a buffer in printable form.