com.dalsemi.tininet
Class TINIDatagramSocket
java.lang.Object
|
+--java.net.DatagramSocket
|
+--com.dalsemi.tininet.TINIDatagramSocket
- public class TINIDatagramSocket
- extends java.net.DatagramSocket
This subclass of DatagramSocket
is a faster and memory conserving version
of java.net.DatagramSocket
.
TINIDatagramSocket
is a direct drop-in
replacement. The receive()
method is
the only method behaving slightly differently. Unlike
its superclass, TINIDatagramSocket.receive(p)
does not allocate a new InetAddress
object
when the DatagramPacket
p's address
is not null.
Constructor Summary |
TINIDatagramSocket()
Constructs a TINIDatagramSocket and binds
it to any available port on the local host machine. |
TINIDatagramSocket(int port)
Constructs a TINIDatagramSocket and binds
it to the specified port on the local host machine. |
TINIDatagramSocket(int port,
java.net.InetAddress laddr)
Constructs a TINIDatagramSocket and binds
it to the specified port and the specified address
on the local host machine. |
Method Summary |
void |
receive(java.net.DatagramPacket p,
byte[] address,
int offset)
Calls the superclass receive function, but also
provides an opportunity to store the incoming packet sender's
address in such a way that you can access the address data
allocating any new memory. |
void |
setInternalAddress(byte[] addr,
int offset,
int length)
Sets an internal address structure. |
Methods inherited from class java.net.DatagramSocket |
close,
getLocalAddress,
getLocalPort,
getSoTimeout,
receive,
send,
setSoTimeout |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
TINIDatagramSocket
public TINIDatagramSocket()
throws java.net.SocketException
- Constructs a
TINIDatagramSocket
and binds
it to any available port on the local host machine.
- Throws:
- java.net.SocketException - if the socket could not be opened, or the
socket bind operation failed.
TINIDatagramSocket
public TINIDatagramSocket(int port)
throws java.net.SocketException
- Constructs a
TINIDatagramSocket
and binds
it to the specified port on the local host machine.
- Parameters:
port
- local port to use.- Throws:
- java.net.SocketException - if the socket could not be opened, or the
socket could not bind to the specified local port.
TINIDatagramSocket
public TINIDatagramSocket(int port,
java.net.InetAddress laddr)
throws java.net.SocketException
- Constructs a
TINIDatagramSocket
and binds
it to the specified port and the specified address
on the local host machine.
- Parameters:
port
- local port to use.laddr
- local address to use.- Throws:
- java.net.SocketException - if the socket could not be opened, or the
socket could not bind to the specified local port and address.
receive
public void receive(java.net.DatagramPacket p,
byte[] address,
int offset)
throws java.io.IOException
- Calls the superclass
receive
function, but also
provides an opportunity to store the incoming packet sender's
address in such a way that you can access the address data
allocating any new memory. The only non-memory way to get an
address out of an InetAddress structure is to call the
getAddress
function, which mallocs an array.
This function provides an alternative.
The socket data stored in address
consists of 18 bytes:
16 bytes of IP address (an IPv4 address is the last 4 bytes of this 16),
and 2 bytes for the port number, MSB first.
- Parameters:
p
- packet that will receive the datagramaddress
- byte array to store address dataoffset
- offset into byte array to copy socket data- Throws:
- java.io.IOException - if an I/O error occurs
setInternalAddress
public void setInternalAddress(byte[] addr,
int offset,
int length)
- Sets an internal address structure. Should not be called by
user code. This function is public only so that the core Java
API can call it.
- Parameters:
addr
- offset
- length
-
Also see:
o TINI 1.16 API, Optional Modules
o TINI Home Page
o 1-Wire API
o JDK 1.1
Last update Wed Jun 8 17:19:36 CDT 2005