Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| J2ME CDC
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.microedition.io
Interface DatagramConnection

All Superinterfaces:
  Connection

public interface DatagramConnection
extends Connection

This interface defines the capabilities that a datagram connection must have.

The parameter string describing the target of the connection takes the form:

    {protocol}:[//{host}]:{port}

A datagram connection can be opened in a "client" mode or a "server" mode. If the "//{host}" is missing then it is opened as a "server" (by "server", this means that a client application initiates communication). When the "//{host}" is specified the connection is opened as a client.

Examples:

A datagram connection for accepting datagrams
datagram://:1234

A datagram connection for sending to a server:
datagram://123.456.789.12:1234

Note that the port number in "server mode" (unspecified host name) is that of the receiving port. The port number in "client mode" (host name specified) is that of the target port. The reply to port in both cases is never unspecified. In "server mode", the same port number is used for both receiving and sending. In "client mode", the reply-to port is always dynamically allocated.

Method Summary
`int` | `getMaximumLength()` Get the maximum length a datagram can be.
`int` | `getNominalLength()` Get the nominal length of a datagram.
`Datagram` | `newDatagram(byte[] buf, int size)` Make a new datagram object
`Datagram` | `newDatagram(byte[] buf, int size, String addr)` Make a new datagram object
`Datagram` | `newDatagram(int size)` Make a new datagram object automatically allocating a buffer
`Datagram` | `newDatagram(int size, String addr)` Make a new datagram object
`void` | `receive(Datagram dgram)` Receive a datagram
`void` | `send(Datagram dgram)` Send a datagram

Methods inherited from interface javax.microedition.io.Connection
`close`

Method Detail

### getMaximumLength

    public int getMaximumLength()
                         throws IOException

  Get the maximum length a datagram can be.
  Returns:
    address The length.

### getNominalLength

    public int getNominalLength()
                         throws IOException

  Get the nominal length of a datagram.
  Returns:
    address The length.

### send

    public void send(Datagram dgram)
              throws IOException

  Send a datagram
  Parameters:
    `dgram` - A datagram.
  Throws:
    `IOException` - If an I/O error occurs.
    `InterruptedIOException` - Timeout or upon closing the connection with outstanding I/O.

### receive

    public void receive(Datagram dgram)
                 throws IOException

  Receive a datagram
  Parameters:
    `dgram` - A datagram.
  Throws:
    `IOException` - If an I/O error occurs.
    `InterruptedIOException` - Timeout or upon closing the connection with outstanding I/O.

### newDatagram

    public Datagram newDatagram(int size)
                         throws IOException

  Make a new datagram object automatically allocating a buffer
  Parameters:
    `size` - The length of the buffer to be allocated for the datagram
  Returns:
    A new datagram

### newDatagram

    public Datagram newDatagram(int size,
                                String addr)
                         throws IOException

  Make a new datagram object
  Parameters:
    `size` - The length of the buffer to be used
    `addr` - The address to which the datagram must go
  Returns:
    A new datagram

### newDatagram

    public Datagram newDatagram(byte[] buf,
                                int size)
                         throws IOException

  Make a new datagram object
  Parameters:
    `buf` - The buffer to be used in the datagram
    `size` - The length of the buffer to be allocated for the datagram
  Returns:
    A new datagram
  Throws:
    `IllegalArgumentException` - if the length is negative or larger than the buffer

### newDatagram

    public Datagram newDatagram(byte[] buf,
                                int size,
                                String addr)
                         throws IOException

  Make a new datagram object
  Parameters:
    `buf` - The buffer to be used in the datagram
    `size` - The length of the buffer to be used
    `addr` - The address to which the datagram must go
  Returns:
    A new datagram
  Throws:
    `IllegalArgumentException` - if the length is negative or larger than the buffer

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| J2ME CDC
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Java is a trademark or registred trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2000 Sun Microsystems, Inc. 901 San Antonio Road,
Palo, Alto, California, 94303, U.S.A All Rights Reserved.