1. Trang chủ
  2. » Công Nghệ Thông Tin

MIDP Programming pptx

41 154 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

MIDP Programming Networking Networking Chapter Objectives The CLDC Streams Model The CLDC Streams Model Generic Connection Framework (GCF) Generic Connection Framework (GCF) Supported Protocols Supported Protocols Creating a Connection Creating a Connection Review of HTTP Review of HTTP Making an HTTP Request Making an HTTP Request Building a CGI String Building a CGI String Design Tips Design Tips Differences between J2ME and J2SE Networking Differences between J2ME and J2SE Networking The CLDC Streams Model In MIDP, as in J2SE, IO streams are the primary mechanism In MIDP, as in J2SE, IO streams are the primary mechanism available to applications to read and write streams of data. available to applications to read and write streams of data. In addition to java.io, the MIDP defines the In addition to java.io, the MIDP defines the javax.microedition.io package in contrast to java.net, which javax.microedition.io package in contrast to java.net, which supports networking and communications for MIDP supports networking and communications for MIDP applications. applications. MIDP applications use the javax.microedition.io types to create MIDP applications use the javax.microedition.io types to create and manipulate various kinds of network connections. and manipulate various kinds of network connections. They then read from these connections and write to them using They then read from these connections and write to them using the types in the MIDP java.io package, which contains a subset the types in the MIDP java.io package, which contains a subset of the classes and interfaces in the J2SE java.io package. of the classes and interfaces in the J2SE java.io package. Generic Connection Framework CLDC specifies a CLDC specifies a generic connection generic connection mechanism mechanism Leaves considerable Leaves considerable flexibility to flexibility to implementations implementations Capable of supporting Capable of supporting many different kinds of many different kinds of connections, from serial connections, from serial ports through wireless ports through wireless networking networking The fundamental idea: The fundamental idea: Give an URL-like string Give an URL-like string to the framework to the framework Get back something that Get back something that has input and output has input and output streams streams Connection and its Family Connection represents some kind of I/O connection Connection represents some kind of I/O connection It has subinterfaces that define more specific connection types It has subinterfaces that define more specific connection types Making a Connection Connector is a Connection factory Connector is a Connection factory Pass a URL-style string to open(), get back some Pass a URL-style string to open(), get back some Connection implementation Connection implementation MIDP says that HTTP must be supported MIDP says that HTTP must be supported Other connection types are optional Other connection types are optional Note that HTTP does not have to run over TCP/IP Note that HTTP does not have to run over TCP/IP Connection protocol support Connector.Open("socket://www.corej2me.com.com:55"); Connector.Open("socket://www.corej2me.com.com:55"); Connector.Open("http://www.corej2me.com"); Connector.Open("http://www.corej2me.com"); Connector.Open("datagram://www.corej2me.com:1000"); Connector.Open("datagram://www.corej2me.com:1000"); Connector.Open("file://makefile.txt"); Connector.Open("file://makefile.txt"); Opening a connection public static Connection open(String name) public static Connection open(String name) public static Connection open(String name, int mode) public static Connection open(String name, int mode) public static Connection open(String name, int mode, public static Connection open(String name, int mode, boolean timeouts) boolean timeouts) Opening a connection public static DataInputStream public static DataInputStream openDataInputStream(String name) openDataInputStream(String name) public static DataOutputStream public static DataOutputStream openDataOutputStream(String name) openDataOutputStream(String name) public static InputStream openInputStream(String name) public static InputStream openInputStream(String name) public static OutputStream openOutputStream(String public static OutputStream openOutputStream(String name) name) Opening a connection //Create connection //Create connection ContentConnection connection = (ContentConnection) ContentConnection connection = (ContentConnection) Connector.open("http://www.corej2me.com" ); Connector.open("http://www.corej2me.com" ); // With the connection, open a stream // With the connection, open a stream InputStream iStrm = connection.openInputStream(); InputStream iStrm = connection.openInputStream(); // ContentConnection includes a length method // ContentConnection includes a length method int length = (int) connection.getLength(); int length = (int) connection.getLength(); if (length != -1) { if (length != -1) { byte imageData[] = new byte[length]; byte imageData[] = new byte[length]; // Read the data into an array // Read the data into an array iStrm.read(imageData); iStrm.read(imageData); } } [...]... imageData[] = bStrm.toByteArray(); // Create the image from the byte array img = Image.createImage(imageData, 0, imageData.length); HTTP support in MIDP HTTP support in MIDP The original MIDP 1.0 specification only required that devices support the HTTP connection protocol MIDP 2.0 spec requires support for both HTTP and HTTPS The APIs to work with these protocols are HttpConnection and HttpConnections, respectively... sends response Requests and responses have two parts: Headers (metadata) Content Requests often have no content Requests can contain parameters Think of the values from an HTML form HTTP Connections The MIDP profile supports HTTP version 1.1 connections via the HttpConnection interface The GET, POST, and HEAD schemes of HTTP are supported Parameters For GET, parameters are encoded and tacked on to the . and communications for MIDP supports networking and communications for MIDP applications. applications. MIDP applications use the javax.microedition.io types to create MIDP applications use. Image.createImage(imageData, 0, imageData.length); } } HTTP support in MIDP HTTP support in MIDP The original MIDP 1.0 specification only required that The original MIDP 1.0 specification only required that devices. applications to read and write streams of data. In addition to java.io, the MIDP defines the In addition to java.io, the MIDP defines the javax.microedition.io package in contrast to java.net,

Ngày đăng: 08/08/2014, 10:20

Xem thêm: MIDP Programming pptx

Mục lục

    The CLDC Streams Model

    Connection and its Family

    HTTP support in MIDP

    Request and response protocols

    Accessing a Java servlet

    Invoking a CGI Script

    Differences between J2ME and J2SE Networking

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN