Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Scmad Chapter09

1.028 visualizaciones

Publicado el

Chapter 09 - SCMAD Certification Material - Only for studies purposes

Publicado en: Tecnología, Educación
  • Sé el primero en comentar

Scmad Chapter09

  1. 1. By Marcel Caraciolo Chapter 09– Generic Connection Framework (GCF) SCMAD Certification 45mm 61mm
  2. 2. Agenda <ul><li>CLDC - GCF </li></ul><ul><ul><li>Generic Connection Framework </li></ul></ul><ul><ul><li>Connector </li></ul></ul><ul><ul><li>Connection, InputConnection, OutputConnection </li></ul></ul><ul><ul><li>StreamConnection, ContentConnection </li></ul></ul><ul><ul><li>DatagramConnection </li></ul></ul><ul><ul><li>Datagram </li></ul></ul><ul><ul><li>StreamConnectionNotifier </li></ul></ul><ul><ul><li>Exceptions </li></ul></ul>
  3. 3. Generic Connection Framework <ul><li>Package is incomplete and is missing from CLDC. Communications are done using “Generic Connection Framework”. </li></ul><ul><li>Package: </li></ul><ul><li>Based on Connection interface. Every connection extends this interface </li></ul><ul><li>No protocol implementation is defined, only interfaces are specified. </li></ul>
  4. 4. GCF: Classes <ul><li>Connector </li></ul><ul><ul><li>Factory to create connections from URL’s </li></ul></ul><ul><ul><li>Methods: </li></ul></ul><ul><ul><ul><li>open (name): Open a URL for reading and writing </li></ul></ul></ul><ul><ul><ul><li>open( name,mode ): mode= READ,WRITE or READ_WRITE. Opens a connection on a specific mode. Default is READ_WRITE. </li></ul></ul></ul><ul><ul><ul><li>open( name,mode,timeouts): Timeouts shall occur. There is no way to control the timeout period. Default is false. </li></ul></ul></ul><ul><ul><ul><li>openDataInputStream( name), openDataOutputStream( name) openInputStream( name), openOutputStream( name): Returns streams instead of Connections. May be simpler when we are only reading from or writing to a resource </li></ul></ul></ul>
  5. 5. GCF: Classes <ul><li>Connection </li></ul><ul><ul><li>All other interfaces extends this one, Only defines “close” operation </li></ul></ul><ul><li>InputConnection </li></ul><ul><ul><li>Connection that allows reading from streams </li></ul></ul><ul><ul><li>Methods: openInputStream(), openDataInputStream(): Open read-only streams. </li></ul></ul><ul><li>OutputConnection: </li></ul><ul><ul><li>Connection that allows writing to streams </li></ul></ul><ul><ul><li>Methods: openOutputStream(),openDataOutputStream(): Open write-only streams </li></ul></ul>
  6. 6. Interfaces <ul><li>StreamConnection </li></ul><ul><ul><li>Defines no methods. Simply extends InputConnection and OutputConnection defining a connection that allows both writing and reading to streams(e.g. TCP Socket). </li></ul></ul><ul><li>ContentConnection </li></ul><ul><ul><li>Extends StreamConnection. Allows reading, writing and is also content-oriented (e.g.HTTP) </li></ul></ul><ul><ul><li>Methods: </li></ul></ul><ul><ul><ul><li>getType(): Type of the requested object </li></ul></ul></ul><ul><ul><ul><li>getEnconding(): Content encoding </li></ul></ul></ul><ul><ul><ul><li>getLength(): Size of the requested object </li></ul></ul></ul>
  7. 7. GCF: High Level Architecture
  8. 8. GCF: Basic Architecture
  9. 9. DatagramConnection <ul><li>Connection for sending and receiving datagrams (e.g. UDP) </li></ul><ul><li>May be opened as “client” or “server”. To open a server connection you simply hide the destination address on the URL. For instance: </li></ul><ul><ul><li>Client: “ datagram://”  Can only send datagrams to this machine </li></ul></ul><ul><ul><li>Server: “ datagram://:1234”  Can receive and send datagrams to any machine </li></ul></ul>
  10. 10. DatagramConnection <ul><li>getMaximumLength(): Maximum size a datagram may have, in bytes </li></ul><ul><li>newDatagram(size): Creates a new datagram with the specified size </li></ul><ul><li>newDatagram (size,address): Creates a datagram addressed to the specified destination </li></ul><ul><li>newDatagram( buffer[],size): Creates a datagram with the specified payload </li></ul><ul><li>newDatagram( buffer[], size, address ): Creates a datagram with specified address and payload </li></ul>
  11. 11. DatagramConnection: Methods <ul><li>send (datagram): Send the datagram. The object must have destination address and payload set </li></ul><ul><li>receive( datagram): Blocks until a datagram is received. Data from this message is written on the datagram passed as parameter. If the datagram is smaller than the received message, data is lost (the array is truncated). </li></ul>
  12. 12. Datagram <ul><li>Represents a datagram was received, or a datagram to be sent. It has address and payload. </li></ul><ul><li>Extends DataInput and DataOutput, so the payload may be managed directly by writeXXX() and readXXX()methods </li></ul><ul><li>Instances may be used for sending and receiving, changing only the required parts(payload, size, address) </li></ul>
  13. 13. Datagram: methods <ul><li>getAddress(): Destination or origin address </li></ul><ul><li>getData(): Payload </li></ul><ul><li>setData( buffer[],offset,length ): Sets the payload </li></ul><ul><li>getLength(): Payload size </li></ul><ul><li>setLength( length ): Changes the payload size </li></ul><ul><li>setAddress( address): Sets the address </li></ul><ul><li>setAddress( datagram): Copies the address from the parameter </li></ul><ul><li>reset(): Resets DataInput and DataOutput pointers, returning the message to its original state </li></ul>
  14. 14. StreamConnectionNotifier <ul><li>Wait for stream connections (e.g. TCP socket) </li></ul><ul><li>Method: acceptAndOpen(): Blocks until a connection is received </li></ul>
  15. 15. Exceptions <ul><li>ConnectionNotFoundException: Throws when a protocol is not supported </li></ul>
  16. 16. MIDP: Generic Connection Framework <ul><li>Implements protocol over CLDC’s GCF </li></ul><ul><li>Required protocols: HTTP and HTTPS  This does not mean that TCP-IP must be supported. HTTP may be “tunneled” over any other protocol </li></ul><ul><li>Optional protocols: TCP Sockets, SSL Sockets, COMM, UDP </li></ul>
  17. 17. MIDP: Generic Connection Framework <ul><li>Portable applications shall rely only on HTTP and HTTPS availability. You shall remember that mobile phones usually are not inside TCP-IP networks and that network usage is billed to the user </li></ul><ul><li>Network communications are slow operations, and therefore they shall never be called on the application’s thread. Separate threads shall ALWAYS be used when calling the network </li></ul><ul><li>Classes at package </li></ul>
  18. 18. HttpConnection <ul><li>Extends ContentConnection, accesses HTTP resources </li></ul><ul><li>Opened with“ http://...”) </li></ul><ul><li>Can be on one of the following states: </li></ul><ul><ul><li>setup: It was opened, but the request was not sent yet. Request parameters must be set at this state </li></ul></ul><ul><ul><li>connected: Request header was sent. It switches to this state when any method that asks for response information is called. </li></ul></ul><ul><ul><li>closed: Finished. Switches to it when close is called. </li></ul></ul>
  19. 19. HttpConnection <ul><li>You cannot request more than one resource through the same connection ( HTTP 1.1). After a resource is requested, the connection must be closed and another one must be created if the new resource is to be loaded </li></ul><ul><li>To use authentication, the APPLICATION itself must set the “Authorization””header with the username and password values coded in Base64 ( there is no support on the platform to perform this enconding) </li></ul><ul><li>Methods that may only be called at “ setup” state: </li></ul><ul><ul><li>setRequestMethod( method): GET,POST or HEAD. Default is GET. </li></ul></ul><ul><ul><li>setRequestProperty( key,value): Sets a request property </li></ul></ul>
  20. 20. HttpConnection: Methods (Connected) <ul><li>openInputStream, openOutputStream, </li></ul><ul><li>openDataInputStream, openDataOutputStream: Inherited from StreamConnection. Gets an input or output stream(OutputStream: only valid for POST. Content-length parameter must be sent. Cannot be used after InputStream has been used) </li></ul><ul><li>getLength(), getType(), getEnconding(): Inherited from ContentConnection. Return the content-length, content-type and content-enconding header values </li></ul><ul><li>getHeaderField( name ): Gets a header value from its name </li></ul>
  21. 21. HttpConnection: Methods (Connected) <ul><li>getHeaderFieldInt( name,def), getHeaderFieldDate( name,def): Returns the header value in the desired format. A default value is passed as parameter, and it’s returned if the field is not available or is malformed. </li></ul><ul><li>getHeaderField( n ), getHeaderFieldKey( n ): Return the name or value of the nth field </li></ul><ul><li>getResponseCode(): Response status code(e.g. 200,404,etc). </li></ul><ul><li>getResponseMessage(): Response status message (e.g. “OK”, “Not Found”, etc) </li></ul><ul><li>getExpiration(),getDate(), getLastModified(): Value of the expires, date and last- modified headers </li></ul>
  22. 22. HttpConnection: Methods (Any time) <ul><li>getURL():Connection URL, defined when the connection is create </li></ul><ul><li>getProtocol(): Connection protocol (e.g. http, https) </li></ul><ul><li>getHost(), getPort(): Host and port (e.g. </li></ul><ul><li>getFile(): Requested “file” (e.g. page.html) </li></ul><ul><li>getRef(): URL reference (part after “#”) </li></ul><ul><li>getQuery(): URL’s query(parameters, part after the question </li></ul><ul><li>mark). </li></ul><ul><li>getRequestMethod(): Request method( HEAD, GET or POST) </li></ul><ul><li>getRequestProperty(key): Value from a request property </li></ul>
  23. 23. Ht HttpsConnection <ul><li>Extends HttpConnection. Access safe HTTP resources (HTTP over TLS) </li></ul><ul><li>Opened with“ https://...”“) </li></ul><ul><li>Has a very similar API to HTTP, adds only one method to return SecurityInfo (this changes the connection to “connected” state) </li></ul><ul><li>SecurityInfo: Details about a safe connection (server certificate, protocol) </li></ul>
  24. 24. Ht SocketConnection <ul><li>Extends StreamConnection. Defines TCP socket CLIENTS </li></ul><ul><li>Opened with“ socket://host: port...”“) </li></ul><ul><li>Adds methods to set socket options and to check local and remote addresses. </li></ul>
  25. 25. Ht ServerSocketConnection <ul><li>Extends StreamConnectionNotifier. Defines TCP socket SERVERS </li></ul><ul><li>Opened with“ socket://: port...”“) (Host is omitted) </li></ul><ul><li>Defines methods for checking the local host and port. If the port is not passed on the URL, an arbitrary port is chosen by the system </li></ul><ul><li>Method acceptAndOpen returns SocketConnection </li></ul>
  26. 26. Ht SecureConnection <ul><li>Extends SocketConnection, and provide access to SSL sockets (TLS) </li></ul><ul><li>Opened with“ ssl:// …”) </li></ul><ul><li>Similar API to Socket’s, adds only one method to return a SecurityInfo </li></ul>
  27. 27. Ht UDPDatagramConnection <ul><li>Extends DatagramConnection. Sends and receives UDP datagrams </li></ul><ul><li>Adds methods to check the local port and address </li></ul><ul><li>Opened with“ datagram: // …”) </li></ul>
  28. 28. Ht CommConnection <ul><li>Extends StreamConnection, adding methods to configure Baud Rate </li></ul><ul><li>Accesses serial and infra-red ports </li></ul><ul><li>Opened with“ comm: …”) . E.g.“ comm: com0; baudrate = 9600”) </li></ul><ul><li>Configuration parameters: baudrate, bitsperchar, stopbits, parity, etc. </li></ul>
  29. 29. Ht CommConnection <ul><li>To check all available ports, you can check the “ microedition.commports” system parameter. Ports are comma-separated. </li></ul><ul><li>Naming conventions: </li></ul><ul><ul><li>RS – 232 ports: COM# </li></ul></ul><ul><ul><li>IrDA IRCOMM ports: IR# </li></ul></ul>
  30. 30. Ht GCF: Classes Diagram
  31. 31. Example Codes <ul><li>Some examples and MIDlets samples are available for reference and studying at this link: </li></ul><ul><ul><li> </li></ul></ul><ul><li>The source codes include: </li></ul><ul><ul><li>HttpMIDlet </li></ul></ul><ul><ul><li>SocketMIDlet </li></ul></ul><ul><ul><li>UDPMidlet </li></ul></ul>
  32. 32. Future Work <ul><li>Next Chapter: </li></ul><ul><ul><li>WMA </li></ul></ul><ul><ul><ul><li>Wireless Messaging API </li></ul></ul></ul><ul><ul><ul><li>Message Connection </li></ul></ul></ul><ul><ul><ul><li>Message Types </li></ul></ul></ul><ul><ul><ul><li>Classes </li></ul></ul></ul><ul><ul><ul><li>Permissions </li></ul></ul></ul>
  33. 33. References <ul><li>ALVES F. Eduardo. SCMAD Study Guide, </li></ul><ul><li>27/04/2008. </li></ul><ul><li>JAKL Andreas, Java Platform, Micro Edition Part </li></ul><ul><li>01 slides, 12/2007. </li></ul><ul><li>Sun Certification Mobile Application Developer </li></ul><ul><li>Website: []. </li></ul>