|
|||||||||
前のクラス 次のクラス | フレームあり フレームなし | ||||||||
概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド |
Objectcom.docomostar.io.IrServerObexConnection
public class IrServerObexConnection
OBEX サーバとして赤外線通信を行う場合の接続を定義します。
端末によっては、 IrDA 通信に加え IrSimple 片方向通信と IrSimple 双方向通信をサポートします。
IrSimple 通信機能では、クライアントの通信モードに応じてサーバの通信モードが決まります。
接続確立後、getCommMode()
を呼び出すことで通信モードを確認することができます。
IrSimple 片方向通信と IrSimple 双方向通信においては、 オペレーションとして PUT と DISCONNECT をサポートしています。
以下にコード例を示します。
try { IrServerObexConnection soc; soc = (IrServerObexConnection)Connector.open("obex:/irserver"); soc.accept(); // IrDA または IrSimple の場合、この時点でデバイスに通電して // CONNECT オペレーションの待ち状態に入ります。 while (true) { // 複数のオペレーションを行う場合のループ soc.receiveRequest(); // このメソッドから戻った時点で // リクエストが到着しています。 int operation = soc.getOperation(); if (operation == ObexConnection.PUT) { String name = soc.getName(); InputStream in = soc.openInputStream(); // 読み出し処理 in.close(); soc.sendResponse(ObexConnection.SUCCESS); } else if (operation == ObexConnection.GET) { String name = soc.getName(); OutputStream out = soc.openOutputStream(); // 書き込み処理 out.close(); soc.sendResponse(ObexConnection.SUCCESS); } else if (operation == ObexConnection.DISCONNECT) { break; } } soc.close(); } catch (IOException e) { }
フィールドの概要 |
---|
メソッドの概要 | |
---|---|
void |
accept()
接続要求を待ちます。 |
void |
close()
CLDC の仕様に従ってこの接続をクローズする処理を実装します。 |
int |
getCommMode() [iアプリオプションAPI]
接続確立後の通信モードを取得します。 |
int |
getContentLength()
コンテンツの長さを取得します。 |
String |
getName()
NAME ヘッダを取得します。 |
int |
getOperation()
リクエストのオペレーションを取得します。 |
long |
getTime()
TIME ヘッダを取得します。 |
String |
getType()
TYPE ヘッダを取得します。 |
java.io.DataInputStream |
openDataInputStream()
CLDC の仕様に従って DataInputStream オブジェクトを返す処理を実装します。 |
java.io.DataOutputStream |
openDataOutputStream()
CLDC の仕様に従って DataOutputStream オブジェクトを返す処理を実装します。 |
java.io.InputStream |
openInputStream()
CLDC の仕様に従って InputStream オブジェクトを返す処理を実装します。 |
java.io.OutputStream |
openOutputStream()
CLDC の仕様に従って OutputStream オブジェクトを返す処理を実装します。 |
void |
receiveRequest()
リクエストの受信を完了するのを待ちます。 |
void |
sendResponse(int code)
レスポンスを送信します。 |
void |
setName(String name)
NAME ヘッダを設定します。 |
void |
setTime(long time)
TIME ヘッダを設定します。 |
void |
setType(String type)
TYPE ヘッダを設定します。 |
クラス Object から継承されたメソッド |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
メソッドの詳細 |
---|
public void accept() throws java.io.IOException
ServerObexConnection
内の accept
RuntimeException
-
ConnectionException
- ConnectionException
- java.io.InterruptedIOException
-
IllegalStateException
-
ConnectionException
- ConnectionException
- ConnectionException
- ConnectionException
- ConnectionException
- ConnectionException
- java.io.IOException
-
java.io.IOException
-
java.io.IOException
-
public int getOperation()
ServerObexConnection
内の getOperation
RuntimeException
-
public void receiveRequest() throws java.io.IOException
リクエストの受信を完了するのを待ちます。 このメソッドを呼び出すと、リクエストが到着するまでブロックして、 リクエストを全て受信し終わったらこのメソッドから戻ります。 このメソッドから正常に戻った場合は、 クライアントに対してレスポンスを送信するために、必ず sendResponse メソッドを呼ばなければなりません。
このメソッドを呼び出すことによって、それより前にこの接続オブジェクトから 取り出した InputStream, DataInputStream, OutputStream, DataOutputStream が無効になります。 次に InputStream, DataInputStream を取り出した時は、 このリクエストで受信したデータを読み出す入力ストリームを返します。 また、次に OutputStream, DataOutputStream を取り出した時は、 このレスポンスで送信するデータを書き込む出力ストリームを返します。
なお、IrSimple 片方向通信は実際にクライアントに対するレスポンスを送信しませんが、 このメソッドを呼び出した後に、必ず sendResponse メソッドを呼ばなければなりません。
ServerObexConnection
内の receiveRequest
RuntimeException
-
java.io.InterruptedIOException
-
ConnectionException
- ConnectionException
- java.io.IOException
-
java.io.IOException
-
public void sendResponse(int code) throws java.io.IOException
ミニマムスペックでは、以下のレスポンスコードがサポートされています。
ObexConnection.SUCCESS
ObexConnection.NON_AUTHORITATIVE_INFORMATION
ObexConnection.UNAUTHORIZED
ObexConnection.FORBIDDEN
ObexConnection.NOT_FOUND
ObexConnection.REQUEST_TIME_OUT
ObexConnection.CONFLICT
ObexConnection.NOT_IMPLEMENTED
ObexConnection.BAD_REQUEST
ObexConnection.DATABASE_FULL
ObexConnection.DATABASE_LOCKED
ServerObexConnection
内の sendResponse
code
- レスポンスコードを指定します。
RuntimeException
-
ConnectionException
- IllegalArgumentException
-
java.i>
ObexConnection.NON_AUTHORITATIVE_INFORMATION
ObexConnection.UNAUTHORIZED
ObexConnection.FORBIDDEN
ObexConnection.NOT_FOUND
ObexConnection.REQUEST_TIME_OUT
ObexConnection.CONFLICT
ObexConnection.NOT_IMPLEMENTED
ObexConnection.BAD_REQUEST
ObexConnection.DATABASE_FULL
ObexConnection.DATABASE_LOCKED