# DatagramSocketImpl

public abstract class **DatagramSocketImpl** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [SocketOptions](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html) Abstract datagram and multicast socket implementation base class.

### Inherited Constant Summary

From interface [java.net.SocketOptions](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html)

|---|---|---|
| int | [IP_MULTICAST_IF](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#IP_MULTICAST_IF) | Set which outgoing interface on which to send multicast packets. |
| int | [IP_MULTICAST_IF2](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#IP_MULTICAST_IF2) | Same as above. |
| int | [IP_MULTICAST_LOOP](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#IP_MULTICAST_LOOP) | This option enables or disables local loopback of multicast datagrams. |
| int | [IP_TOS](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#IP_TOS) | This option sets the type-of-service or traffic class field in the IP header for a TCP or UDP socket. |
| int | [SO_BINDADDR](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_BINDADDR) | Fetch the local address binding of a socket (this option cannot be "set" only "gotten", since sockets are bound at creation time, and so the locally bound address cannot be changed). |
| int | [SO_BROADCAST](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_BROADCAST) | Sets SO_BROADCAST for a socket. |
| int | [SO_KEEPALIVE](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_KEEPALIVE) | When the keepalive option is set for a TCP socket and no data has been exchanged across the socket in either direction for 2 hours (NOTE: the actual value is implementation dependent), TCP automatically sends a keepalive probe to the peer. |
| int | [SO_LINGER](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_LINGER) | Specify a linger-on-close timeout. |
| int | [SO_OOBINLINE](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_OOBINLINE) | When the OOBINLINE option is set, any TCP urgent data received on the socket will be received through the socket input stream. |
| int | [SO_RCVBUF](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_RCVBUF) | Set a hint the size of the underlying buffers used by the platform for incoming network I/O. |
| int | [SO_REUSEADDR](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_REUSEADDR) | Sets SO_REUSEADDR for a socket. |
| int | [SO_SNDBUF](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_SNDBUF) | Set a hint the size of the underlying buffers used by the platform for outgoing network I/O. |
| int | [SO_TIMEOUT](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#SO_TIMEOUT) | Set a timeout on blocking Socket operations: ``` ServerSocket.accept(); SocketInputStream.read(); DatagramSocket.receive(); ``` The option must be set prior to entering a blocking operation to take effect. |
| int | [TCP_NODELAY](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#TCP_NODELAY) | Disable Nagle's algorithm for this connection. |

### Field Summary

|---|---|---|
| protected [FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html) | [fd](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#fd) | The file descriptor object. |
| protected int | [localPort](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#localPort) | The local port number. |

### Public Constructor Summary

|---|---|
|   | [DatagramSocketImpl](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#DatagramSocketImpl())() |

### Protected Method Summary

|---|---|
| abstract void | [bind](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#bind(int,%20java.net.InetAddress))(int lport, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) laddr) Binds a datagram socket to a local port and address. |
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#close())() Close the socket. |
| void | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#connect(java.net.InetAddress,%20int))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) address, int port) Connects a datagram socket to a remote destination. |
| abstract void | [create](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#create())() Creates a datagram socket. |
| void | [disconnect](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#disconnect())() Disconnects a datagram socket from its remote destination. |
| [FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html) | [getFileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getFileDescriptor())() Gets the datagram socket file descriptor. |
| int | [getLocalPort](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getLocalPort())() Gets the local port. |
| abstract byte | [getTTL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getTTL())() *This method is deprecated. use getTimeToLive instead.* |
| abstract int | [getTimeToLive](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getTimeToLive())() Retrieve the TTL (time-to-live) option. |
| abstract void | [join](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#join(java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) inetaddr) Join the multicast group. |
| abstract void | [joinGroup](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#joinGroup(java.net.SocketAddress,%20java.net.NetworkInterface))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) mcastaddr, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) netIf) Join the multicast group. |
| abstract void | [leave](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#leave(java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) inetaddr) Leave the multicast group. |
| abstract void | [leaveGroup](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#leaveGroup(java.net.SocketAddress,%20java.net.NetworkInterface))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) mcastaddr, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) netIf) Leave the multicast group. |
| abstract int | [peek](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#peek(java.net.InetAddress))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) i) Peek at the packet to see who it is from. |
| abstract int | [peekData](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#peekData(java.net.DatagramPacket))([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p) Peek at the packet to see who it is from. |
| abstract void | [receive](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#receive(java.net.DatagramPacket))([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p) Receive the datagram packet. |
| abstract void | [send](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#send(java.net.DatagramPacket))([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p) Sends a datagram packet. |
| abstract void | [setTTL](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#setTTL(byte))(byte ttl) *This method is deprecated. use setTimeToLive instead.* |
| abstract void | [setTimeToLive](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#setTimeToLive(int))(int ttl) Set the TTL (time-to-live) option. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.net.SocketOptions](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html)

|---|---|
| abstract [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [getOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#getOption(int))(int optID) Fetch the value of an option. |
| abstract void | [setOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOptions.html#setOption(int,%20java.lang.Object))(int optID, [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) value) Enable/disable the option specified by *optID*. |

## Fields

#### protected [FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html)
**fd**

The file descriptor object.

#### protected int
**localPort**

The local port number.

## Public Constructors

#### public
**DatagramSocketImpl**
()

<br />

## Protected Methods

#### protected abstract void
**bind**
(int lport, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) laddr)

Binds a datagram socket to a local port and address.

##### Parameters

| lport | the local port |
| laddr | the local address |
|---|---|

##### Throws

| [SocketException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketException.html) | if there is an error in the underlying protocol, such as a TCP error. |
|---|---|

#### protected abstract void
**close**
()

Close the socket.

#### protected void
**connect**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) address, int port)

Connects a datagram socket to a remote destination. This associates the remote
address with the local socket so that datagrams may only be sent to this destination
and received from this destination. This may be overridden to call a native
system connect.

If the remote destination to which the socket is connected does not
exist, or is otherwise unreachable, and if an ICMP destination unreachable
packet has been received for that address, then a subsequent call to
send or receive may throw a PortUnreachableException.
Note, there is no guarantee that the exception will be thrown.

##### Parameters

| address | the remote InetAddress to connect to |
| port | the remote port number |
|---|---|

##### Throws

| [SocketException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketException.html) | may be thrown if the socket cannot be connected to the remote destination |
|---|---|

#### protected abstract void
**create**
()

Creates a datagram socket.

##### Throws

| [SocketException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketException.html) | if there is an error in the underlying protocol, such as a TCP error. |
|---|---|

#### protected void
**disconnect**
()

Disconnects a datagram socket from its remote destination.

#### protected [FileDescriptor](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/FileDescriptor.html)
**getFileDescriptor**
()

Gets the datagram socket file descriptor.

##### Returns

- a `FileDescriptor` object representing the datagram socket file descriptor

#### protected int
**getLocalPort**
()

Gets the local port.

##### Returns

- an `int` representing the local port value

#### protected abstract byte
**getTTL**
()


**This method is deprecated.**   
use getTimeToLive instead.
Retrieve the TTL (time-to-live) option.

##### Returns

- a byte representing the TTL value

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while retrieving the time-to-live option |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#setTTL(byte)`

#### protected abstract int
**getTimeToLive**
()

Retrieve the TTL (time-to-live) option.

##### Returns

- an `int` representing the time-to-live value

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while retrieving the time-to-live option |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#setTimeToLive(int)`

#### protected abstract void
**join**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) inetaddr)

Join the multicast group.

##### Parameters

| inetaddr | multicast address to join. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while joining the multicast group. |
|---|---|

#### protected abstract void
**joinGroup**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) mcastaddr, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) netIf)

Join the multicast group.

##### Parameters

| mcastaddr | address to join. |
| netIf | specifies the local interface to receive multicast datagram packets |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while joining the multicast group |
|---|---|

#### protected abstract void
**leave**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) inetaddr)

Leave the multicast group.

##### Parameters

| inetaddr | multicast address to leave. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while leaving the multicast group. |
|---|---|

#### protected abstract void
**leaveGroup**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) mcastaddr, [NetworkInterface](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/NetworkInterface.html) netIf)

Leave the multicast group.

##### Parameters

| mcastaddr | address to leave. |
| netIf | specified the local interface to leave the group at |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while leaving the multicast group |
|---|---|

#### protected abstract int
**peek**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) i)

Peek at the packet to see who it is from. Updates the specified `InetAddress`
to the address which the packet came from.

##### Parameters

| i | an InetAddress object |
|---|---|

##### Returns

- the port number which the packet came from.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs |
| [PortUnreachableException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PortUnreachableException.html) | may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
|---|---|

#### protected abstract int
**peekData**
([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p)

Peek at the packet to see who it is from. The data is copied into the specified
`DatagramPacket`. The data is returned,
but not consumed, so that a subsequent peekData/receive operation
will see the same data.

##### Parameters

| p | the Packet Received. |
|---|---|

##### Returns

- the port number which the packet came from.

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs |
| [PortUnreachableException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PortUnreachableException.html) | may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
|---|---|

#### protected abstract void
**receive**
([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p)

Receive the datagram packet.

##### Parameters

| p | the Packet Received. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while receiving the datagram packet. |
| [PortUnreachableException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PortUnreachableException.html) | may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
|---|---|

#### protected abstract void
**send**
([DatagramPacket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramPacket.html) p)

Sends a datagram packet. The packet contains the data and the
destination address to send the packet to.

##### Parameters

| p | the packet to be sent. |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while sending the datagram packet. |
| [PortUnreachableException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/PortUnreachableException.html) | may be thrown if the socket is connected to a currently unreachable destination. Note, there is no guarantee that the exception will be thrown. |
|---|---|

#### protected abstract void
**setTTL**
(byte ttl)


**This method is deprecated.**   
use setTimeToLive instead.
Set the TTL (time-to-live) option.

##### Parameters

| ttl | a byte specifying the TTL value |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while setting the time-to-live option. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getTTL()`

#### protected abstract void
**setTimeToLive**
(int ttl)

Set the TTL (time-to-live) option.

##### Parameters

| ttl | an `int` specifying the time-to-live value |
|---|---|

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O exception occurs while setting the time-to-live option. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/DatagramSocketImpl.html#getTimeToLive()`