このインタフェースでは、データグラム接続に必要な機能を定義します。
接続先を記述するパラメータの文字列に適用される形式は次のとおりです。
{protocol}:[//{host}]:{port}データグラム接続は、「クライアント」モードと「サーバ」モードのどちらでも開始できます。//{host} を省略すると、接続は「サーバ」モードで開始されます (「サーバ」モードとは、クライアントのアプリケーションによって通信が開始されるという意味です)。//{host} を指定すると、接続はクライアントモードで開始されます。
例
データグラムを受信するためのデータグラム接続
datagram://:1234
サーバに送信するためのデータグラム接続
datagram://123.456.789.12:1234
「サーバモード」 (ホスト名の指定なし) のポート番号は、受信ポートのポート番号です。「クライアントモード」 (ホスト名の指定あり) のポート番号は、宛先ポートのポート番号です。どちらの場合も応答先ポートは指定されません。「サーバモード」では、送信と受信の両方に同じポートを使用します。「クライアントモード」では、応答先ポートは必ず動的に割り当てられます。
メソッドの概要 | |
int |
getMaximumLength()
データグラムがとり得る最大の長さを取得します。 |
int |
getNominalLength()
データグラムの標準の長さを取得します。 |
Datagram |
newDatagram(byte[] buf,
int size)
新しいデータグラムオブジェクトを作成します。 |
Datagram |
newDatagram(byte[] buf,
int size,
String addr)
新しいデータグラムオブジェクトを作成します。 |
Datagram |
newDatagram(int size)
新しいデータグラムオブジェクトに対して自動的にバッファを割り当てます。 |
Datagram |
newDatagram(int size,
String addr)
新しいデータグラムオブジェクトを作成します。 |
void |
receive(Datagram dgram)
データグラムを受信します。 |
void |
send(Datagram dgram)
データグラムを送信します。 |
インタフェース javax.microedition.io.Connection から継承したメソッド |
close |
メソッドの詳細 |
public int getMaximumLength() throws IOException
public int getNominalLength() throws IOException
public void send(Datagram dgram) throws IOException
dgram
- データグラムpublic void receive(Datagram dgram) throws IOException
dgram
- データグラムpublic Datagram newDatagram(int size) throws IOException
size
- データグラムに割り当てられるバッファの長さpublic Datagram newDatagram(int size, String addr) throws IOException
size
- 使用されるのバッファの長さaddr
- データグラムの送信先アドレスpublic Datagram newDatagram(byte[] buf, int size) throws IOException
buf
- データグラム内で使用されるバッファsize
- データグラムに割り当てられるバッファの長さpublic Datagram newDatagram(byte[] buf, int size, String addr) throws IOException
buf
- データグラム内で使用されるバッファsize
- 使用されるバッファの長さaddr
- データグラムの送信先アドレス