Android
java.net
public abstract class

java.net.DatagramSocketImpl

java.lang.Object
java.net.DatagramSocketImpl SocketOptions

The abstract superclass of datagram & multicast socket implementations.

Summary

Constants inherited from interface java.net.SocketOptions

Fields

protected      FileDescriptor  fd   
protected      int  localPort   

Public Constructors

            DatagramSocketImpl()
Constructs an unbound datagram socket implementation.

Public Methods

abstract          Object  getOption(int optID)
Answer the nominated socket option.
abstract          void  setOption(int optID, Object val)
Set the nominated socket option.

Protected Methods

abstract          void  bind(int port, InetAddress addr)
Bind the datagram socket to the nominated localhost/port.
abstract          void  close()
Close the socket.
          void  connect(InetAddress inetAddr, int port)
Connect the socket to the specified remote address and port.
abstract          void  create()
This method allocates the socket descriptor in the underlying operating system.
          void  disconnect()
Disconnect the socket from the remote address and port.
          FileDescriptor  getFileDescriptor()
Answer the FileDescriptor, which will be invalid if the socket is closed or not bound.
          int  getLocalPort()
Answer the local port.
abstract          byte  getTTL()
This method is deprecated. Replaced by getTimeToLive()
abstract          int  getTimeToLive()
Answer the time-to-live (TTL) for multicast packets sent on this socket.
abstract          void  join(InetAddress addr)
Add this socket to the multicast group.
abstract          void  joinGroup(SocketAddress addr, NetworkInterface netInterface)
Add this socket to the multicast group.
abstract          void  leave(InetAddress addr)
Remove the socket from the multicast group.
abstract          void  leaveGroup(SocketAddress addr, NetworkInterface netInterface)
Remove the socket from the multicast group.
abstract          int  peek(InetAddress sender)
Peek at the incoming packet to this socket and answer the sender's address into sender.
abstract          int  peekData(DatagramPacket pack)
Receive data into the supplied datagram packet by peeking.
abstract          void  receive(DatagramPacket pack)
Receive data into the supplied datagram packet.
abstract          void  send(DatagramPacket pack)
Sends the supplied datagram packet.
abstract          void  setTTL(byte ttl)
This method is deprecated. Replaced by setTimeToLive(int)
abstract          void  setTimeToLive(int ttl)
Set the time-to-live (TTL) for multicast packets sent on this socket.
Methods inherited from class java.lang.Object
Methods inherited from interface java.net.SocketOptions

Details

Fields

protected FileDescriptor fd

protected int localPort

Public Constructors

public DatagramSocketImpl()

Constructs an unbound datagram socket implementation.

Public Methods

public abstract Object getOption(int optID)

Answer the nominated socket option.

Parameters

optID the socket option to retrieve

Returns

  • Object the option value

Throws

SocketException thrown if an error occurs while accessing the option

public abstract void setOption(int optID, Object val)

Set the nominated socket option.

Parameters

optID the socket option to set
val the option value

Throws

SocketException thrown if an error occurs while setting the option

Protected Methods

protected abstract void bind(int port, InetAddress addr)

Bind the datagram socket to the nominated localhost/port. Sockets must be bound prior to attempting to send or receive data.

Parameters

port the port on the localhost to bind
addr the address on the multihomed localhost to bind

Throws

SocketException if an error occurred during bind, such as if the port was already bound

protected abstract void close()

Close the socket.

protected void connect(InetAddress inetAddr, int port)

Connect the socket to the specified remote address and port.

Parameters

inetAddr the remote address
port the remote port

Throws

SocketException possibly thrown, if the datagram socket cannot be connected to the specified remote address and port

protected abstract void create()

This method allocates the socket descriptor in the underlying operating system.

protected void disconnect()

Disconnect the socket from the remote address and port.

protected FileDescriptor getFileDescriptor()

Answer the FileDescriptor, which will be invalid if the socket is closed or not bound.

Returns

  • FileDescriptor the socket file descriptor

protected int getLocalPort()

Answer the local port. If the socket was bound to any available port, as flagged by a localPort value of -1, query the IP stack.

Returns

  • int the local port to which the socket is bound.

protected abstract byte getTTL()

This method is deprecated. Replaced by getTimeToLive()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns

  • java.net.InetAddress

Throws

IOException The exception description.

See Also

protected abstract int getTimeToLive()

Answer the time-to-live (TTL) for multicast packets sent on this socket.

Returns

  • int

Throws

IOException The exception description.

protected abstract void join(InetAddress addr)

Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters

addr the multicast group to be joined

Throws

IOException may be thrown while joining a group

protected abstract void joinGroup(SocketAddress addr, NetworkInterface netInterface)

Add this socket to the multicast group. A socket must join a group before data may be received. A socket may be a member of multiple groups but may join any group once.

Parameters

addr the multicast group to be joined
netInterface the network interface on which the addresses should be dropped

Throws

IOException may be thrown while joining a group

protected abstract void leave(InetAddress addr)

Remove the socket from the multicast group.

Parameters

addr the multicast group to be left

Throws

IOException May be thrown while leaving the group

protected abstract void leaveGroup(SocketAddress addr, NetworkInterface netInterface)

Remove the socket from the multicast group.

Parameters

addr the multicast group to be left
netInterface the network interface on which the addresses should be dropped

Throws

IOException May be thrown while leaving the group

protected abstract int peek(InetAddress sender)

Peek at the incoming packet to this socket and answer the sender's address into sender. The method will block until a packet is received or timeout expires and returns the sender's port.

Throws

IOException if a read error or timeout occurs

protected abstract int peekData(DatagramPacket pack)

Receive data into the supplied datagram packet by peeking. The data is not removed and will be received by another peekData() or receive() call. This call will block until either data is received or, if a timeout is set, the timeout expires.

Parameters

pack the DatagramPacket used to store the data

Returns

  • the port the packet was received from

Throws

IOException if an error occurs

protected abstract void receive(DatagramPacket pack)

Receive data into the supplied datagram packet. This call will block until either data is received or, if a timeout is set, the timeout expires. If the timeout expires, the InterruptedIOException is thrown.

Throws

IOException if a read error or timeout occurs

protected abstract void send(DatagramPacket pack)

Sends the supplied datagram packet. The packet contains the destination host & port.

Parameters

pack DatagramPacket to send

Throws

IOException if a write error occurs

protected abstract void setTTL(byte ttl)

This method is deprecated. Replaced by setTimeToLive(int)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters

ttl the time-to-live, 0 < ttl <= 255

Throws

IOException The exception thrown while setting the TTL

protected abstract void setTimeToLive(int ttl)

Set the time-to-live (TTL) for multicast packets sent on this socket.

Parameters

ttl the time-to-live, 0 < ttl <= 255

Throws

IOException The exception thrown while setting the TTL
Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:48