Creating a Connection—The Connector Class
In the GCF, connections are established using the class Connector. By passing a URL describing the protocol to the open method of the Connector class, a connection is established. For example, the following line opens a Hypertext Transfer Protocol (HTTP) connection to the address http://java.sun.com:
try { Connection connection = Connector.open ("http://java.sun.com"); } catch (IOException e) { // an error occurred while opening the connection. }
In the case of an error, an IOException is thrown. Most of the GCF methods can throw an IOException in order to report I/O errors to the application.
If the connection is established successfully, an instance of a class implementing the Connection interfaces ...
Get Java™ 2 Micro Edition Application Development now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.