Java Reference
In-Depth Information
// System.out.println("before op close");
op.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
} // while
} // run
}
In Listing 12-3, it would have been possible to use a custom header to send our dating
information. However, this example uses a PUT operation, showing the code required to
handle the more complex OBEX PUT operation instead.
Coding an OBEX Service
The service code and the GUI MIDlet code are in OBEXMIDlet.java , shown in Listing 12-4.
The service is started in its own mServer thread. Note the use of the connect string
“irdaobex://localhost;ias=DatingService” to create the SessionNotifier required to accept
incoming OBEX over IrDA connections.
Listing 12-4. An OBEX Dating Service—OBEXMIDlet.java
import java.io.*;
import javax.microedition.midlet.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;
import javax.obex.*;
import java.io.IOException;
public class OBEXMIDlet
extends MIDlet
implements CommandListener, Runnable {
private DateClient mClient = null;
private Thread mServer = null;
private OperationHandler mOpHandler = null;
private Command mExitCommand = new Command("Exit", Command.EXIT, 2);
private Display mDisplay = null;
private StringItem mDateContact = null;
private Form mForm = null;
Search WWH ::




Custom Search