SlideShare a Scribd company logo
Java™Platform, Micro Edition Part 7Generic Connection Framework, HTTP and Sockets v3.0 – 06 April 2009 1 Andreas Jakl, 2009
Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Java ME courses at the University of Applied Sciences in Hagenberg, Austria at the Mobile Computing department ( http://www.fh-ooe.at/mc ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. This document contains copyright materials which are proprietary to Sun or various mobile device manufacturers, including Nokia, SonyEricsson and Motorola. Sun, Sun Microsystems, the Sun Logo and the Java™ Platform, Micro Edition are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries.  Andreas Jakl, 2009 2
Contents Generic Connection Framework HTTP Connections Sockets Andreas Jakl, 2009 3
Generic Connection Framework Java SE: 150+ classes and interfaces (java.io, java.net) Bytecode-size: java.net 200kB+ Consistency: Different objects for protocols CLDC: Generic Connection Framework (GCF) Unified API for various protocols Profilesdefine protocols (MIDP, additional packages) Mandatory for MIDP 2.0:Hypertext Transfer Protocol (HTTP)Hypertext Transfer Protocol over TLS/SSL (HTTPS) Today: GCF made its way into Java SE (JSR 197) Andreas Jakl, 2009 4
Generic Connection Framework Hierarchy of interfaces and classes to: create connections (HTTP, datagrams, ...) perform I/O GCF used by optional packages Bluetooth, Files, SmartCards, Messaging, …  … might look difficult at first, but is very easy to use! Andreas Jakl, 2009 5
Connector Single Factory-class, creates any type of connection Examples: Connector.open(“http://www.mopius.com/”); Connector.open(“socket://realreplay.mopius.com:5412”); Connector.open(“file://data.txt”); Andreas Jakl, 2009 6 Connector.open(“protocol:address;parameters”);
Connector – Protocols  Protocol is chosen automatically, based on URL GCF searches for class that implements protocol Success: Returns class that implements Connection-interface Failure: ConnectionNotFoundException HTTP is supported for sure, Sockets might be unavailable on phone / through operator Andreas Jakl, 2009 7 Example: HttpConnection con = (HttpConnection) Connector.open (“http://www.mopius.com/”);
Connect and Transfer Short example for sockets (omits error handling): Andreas Jakl, 2009 8 // Open the connection to a URL SocketConnection con = (SocketConnection) Connector.open(“socket://127.0.0.1:5000”); // Send request DataOutputStream dos = con.openDataOutputStream(); dos.writeShort(12); dos.writeUTF(“Hello World”); dos.close(); // Receive answer DataInputStreamdis = con.openDataInputStream(); short msgId = dis.readShort(); dis.close(); // Cleanup con.close();
GCF – High Level Andreas Jakl, 2009 9 Generic way of handlingall communication andall protocols. Generic factory class, common interface Wait for incoming stream connections Stream-based I/O Packet-based I/O GCF (without additional packages like Bluetooth)supports three types of communication Additional content-specific information (data length, content type, data encoding, …) More comfortablefunctions for protocolslike HTTP are available.
GCF – Basic Class Diagram Andreas Jakl, 2009 10 Connection Connector ConnectionNotFoundException Generic factory class, common interface creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Other subtypes… Wait for incoming stream connections Stream-based I/O Packet-based I/O creates Datagram StreamConnection ContentConnection Other subtypes… Other subtypes… Additional content-specific information (data length, content type, data encoding, …) Other subtypes… CLDC
GCF – Basic Class Diagram Andreas Jakl, 2009 11 Connection Connector ConnectionNotFoundException creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Other subtypes… creates Datagram StreamConnection ContentConnection Other subtypes… Other subtypes… Other subtypes… CLDC
GCF – MIDP Class Diagram Andreas Jakl, 2009 12 Connection Connector ConnectionNotFoundException creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Bluetooth Messaging creates Datagram StreamConnection UDPDatagramConnection CommConnection SocketConnection ContentConnection ServerSocketConnection FileConnection HttpConnection SecureConnection HttpsConnection MIDP 2.0 CLDC Optional JSRs
URL Uniform Resource Locator (URL) Identify connection type and endpoint Andreas Jakl, 2009 13 scheme://user:password@host:port/url-path;parameters
URL – Schemes Some of GCF connection types: Andreas Jakl, 2009 14 ... you can only be sure that HTTP(S) is available on a device!
public void commandAction (Command command, Displayable displayable) {     if (command == iCmdConnect) { con = (HttpConnection) Connector.open("http://www.mopius.com/images/mopius.png");     } } Asynchronous Connection Andreas Jakl, 2009 15 Establishing a connection in the command handling function leads to a deadlock!  The user can no longer select “Yes” or “No”. Notification message provided by WTK (console):
Asynchronous Connection Solution: Start own thread for networking code! Andreas Jakl, 2009 16 public class MyClass extends MIDlet implements CommandListener, Runnable {     // … // Process the command to connect to the network     public void commandAction(Command command, Displayable displayable) {         if (command == cmdConnectToWeb) { // Start connection in extra thread  commandAction-function is not blocked new Thread(this).start();         }     } // Connect to the network public void run() { // … HttpConnection con = (HttpConnection)Connector.open(url); // …     } }
Error Handling Connection should always be closed ( Exception!) Andreas Jakl, 2009 17 // Define those two variables outside the try-block, so that they are known in the finally-block! SocketConnection con = null; DataInputStream is = null; try {     con = (SocketConnection)Connector.open(url);		// Open the connection to the requested URL     // … (optional) define the request package and/or send data …     is = con.openDataInputStream();					// Read from the connection // … read from the input stream to process data … } catch (IOException ex) { } finally {     try {         if (is != null)			// Here we make sure that everything that might still be open is closed! is.close();         if (con != null) con.close();     } catch (IOException ex) {	 // This error can usually be ignored, as something else already went wrong…     } }
HyperText Transfer Protocol Information about the Andreas Jakl, 2009 18
HTTP HTTP = Hypertext Transfer Protocol Request/Response-protocol Andreas Jakl, 2009 19 Client submitsRequestHeader, Body, … Server GPRS, UMTS, WLAN, … CallbackResponseHeader, Body, …
HTTP in JavaME Similar to the logical structure: Open a connection Prepare the request message Send request + body (optional, POST only) Retrieve response Close connection (can’t be reused!) Andreas Jakl, 2009 20
HTTP Messages Andreas Jakl, 2009 21 Server
Request Method 3 request methods supported: Andreas Jakl, 2009 22
HTTP Get Andreas Jakl, 2009 23 JavaME-code: String url = "http://www.mopius.com/test.php?user=me&pwd=xxx"; HttpConnection con = (HttpConnection)Connector.open(url); con.setRequestMethod(HttpConnection.GET);	// Define method as GET conn.setRequestProperty("User-Agent", "Mozilla/4.0"); intrc = con.getResponseCode();				// Request is sent with first read-function 									// No write required! HTTP-Request received by the web-server: GET /test.php?user=me&pwd=xxx HTTP/1.1 Host: www.mopius.com User-Agent: Mozilla/4.0
HTTP Post – Form Andreas Jakl, 2009 24 JavaME-code: String url = "http://www.mopius.com/test.php"; String data = "user=me&pwd=xxx";		// Data to send, without & // Special characters have to be URL-encoded manually (e.g. " " -> "%20") HttpConnection con = (HttpConnection)Connector.open(url); con.setRequestMethod(HttpConnection.POST);		// Define method as POST con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("User-Agent", "Mozilla/4.0"); con.setRequestProperty("Content-Length", Integer.toString(data.length())); OutputStreamos = con.openOutputStream(); os.write(data.getBytes()); os.close();// Request is sent when output-stream is closed intrc = con.getResponseCode();		 HTTP-Request received by the web-server: POST /test.php HTTP/1.1 Host: www.mopius.com User-Agent: Mozilla/4.0 Content-Length: 15 Content-Type: application/x-www-form-urlencoded user=me&pwd=xxx
HTTP Post – Raw Data For raw client-server communication: Set content type Create byte array, e.g. using DataOutputStream Andreas Jakl, 2009 25 con.setRequestProperty("Content-Type", "application/octet-stream"); DataOutputStream dos = new DataOutputStream( con.openOutputStream() ); dos.writeBoolean(true); dos.writeUTF("Hello World"); dos.close();
Server Response Status line contains numeric value + text Query response code: Andreas Jakl, 2009 26 intrc = con.getResponseCode(); Overview: HTTP status categories Most important status codes and the respective constants in HttpConnection
Retrieving a HTTP Response Simple version: (creates an image based on stream) Next slide: More complex version Reads response differently, depending on if the length is known Andreas Jakl, 2009 27 // ... send request ... intrc = con.getResponseCode();			// Retrieve HTTP response code if (rc == HttpConnection.HTTP_OK) {		// Response in most cases only available for OK     is = con.openDataInputStream();			// Get the data input stream     Image img = Image.createImage(is);		// Read image }
Retrieving a HTTP Response Andreas Jakl, 2009 28 // ... send request ... intrc = con.getResponseCode();			// Retrieve HTTP response code if (rc == HttpConnection.HTTP_OK) {		// Response in most cases only available for OK     is = con.openDataInputStream();			// Get the data input stream int length = (int)con.getLength();			// Get length of the response - int is enough     byte data[];     if (length > 0) {						// If the server set the content length...         data = new byte[length];			// Do a direct, more efficient read using a fixed byte array inttotalReadBytes = 0;				// is.read() might not read everything at once         while (totalReadBytes < length) {		//  continue reading until expected length is received intcurReadBytes = is.read(data, totalReadBytes, length - totalReadBytes);             if (curReadBytes == -1) break;		// Reached the end before the expected length? totalReadBytes += curReadBytes;         }     } else {							// If the length is unknown, however, use a dynamic stream ByteArrayOutputStreambos = new ByteArrayOutputStream(); intch;         while ((ch = is.read()) != -1) {			// Read each byte until a the end is reached bos.write(ch);					// Append the new character to the byte array output stream         } bos.flush();         data = bos.toByteArray();			// Create a byte array based on the stream bos.close();     } }
Sockets Low-Level Communication Andreas Jakl, 2009 29
Socket Communication Multiplayer games / applications – HTTP? Request / response might not be useful Large overhead through headers Sockets: Server listens at specific port Client connects to server Bidirectional communication possible Andreas Jakl, 2009 30
Streams / Datagrams Stream socket: Uses TCP (Connection-oriented protocol) Open – send/receive ... – Close  Delivery & order of data are guaranteed Datagram socket: Uses UDP (Record-oriented system) Datagram = chunk of data, no stream Delivery not guaranteed Faster than TCP Mobile phone: Performance issues in any case (network speed)! Andreas Jakl, 2009 31
Sockets and Java ME Similar to HTTP: Writing and Reading: Andreas Jakl, 2009 32 TCP-Connection: SocketConnection con = (SocketConnection) Connector.open(“socket://127.0.0.1:5000”); UDP-Connection: UDPDatagramConnection con = (UDPDatagramConnection)Connector.open(“datagram://127.0.0.1:5000”); InputStream is = con.openInputStream(); OutputStreamos = con.openOutputStream(); // … write and read to/from the streams … is.close(); os.close(); con.close();
Thanks for your attention That’s it! Andreas Jakl, 2009 33

More Related Content

Similar to Java ME - 07 - Generic Connection Framework, HTTP and Sockets

Socket Programming
Socket  ProgrammingSocket  Programming
Socket Programmingleminhvuong
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagarNitish Nagar
 
Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19José Paumard
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkbanq jdon
 
Symbian OS - Communication And Messaging
Symbian OS - Communication And MessagingSymbian OS - Communication And Messaging
Symbian OS - Communication And MessagingAndreas Jakl
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming ClientsAdil Jafri
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming ClientsAdil Jafri
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqelajobandesther
 
Review on the Design of Web Based SCADA Systems Based on OPC DA Protocol
Review on the Design of Web Based SCADA Systems Based on OPC DA ProtocolReview on the Design of Web Based SCADA Systems Based on OPC DA Protocol
Review on the Design of Web Based SCADA Systems Based on OPC DA ProtocolCSCJournals
 
Lecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesLecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesMaksym Davydov
 
Java ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsJava ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsAndreas Jakl
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIsJames Pearce
 
Communication in android
Communication in androidCommunication in android
Communication in androideleksdev
 
Manual redes - network programming with j2 me wireless devices
Manual   redes - network programming with j2 me wireless devicesManual   redes - network programming with j2 me wireless devices
Manual redes - network programming with j2 me wireless devicesVictor Garcia Vara
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New EvolutionAllan Huang
 

Similar to Java ME - 07 - Generic Connection Framework, HTTP and Sockets (20)

Socket Programming
Socket  ProgrammingSocket  Programming
Socket Programming
 
Java bad coding practices
Java bad coding practicesJava bad coding practices
Java bad coding practices
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19Loom Virtual Threads in the JDK 19
Loom Virtual Threads in the JDK 19
 
DDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFrameworkDDD Framework for Java: JdonFramework
DDD Framework for Java: JdonFramework
 
Symbian OS - Communication And Messaging
Symbian OS - Communication And MessagingSymbian OS - Communication And Messaging
Symbian OS - Communication And Messaging
 
15network Programming Clients
15network Programming Clients15network Programming Clients
15network Programming Clients
 
Network Programming Clients
Network Programming ClientsNetwork Programming Clients
Network Programming Clients
 
Networking and Data Access with Eqela
Networking and Data Access with EqelaNetworking and Data Access with Eqela
Networking and Data Access with Eqela
 
Review on the Design of Web Based SCADA Systems Based on OPC DA Protocol
Review on the Design of Web Based SCADA Systems Based on OPC DA ProtocolReview on the Design of Web Based SCADA Systems Based on OPC DA Protocol
Review on the Design of Web Based SCADA Systems Based on OPC DA Protocol
 
Java networking
Java networkingJava networking
Java networking
 
Android session-5-sajib
Android session-5-sajibAndroid session-5-sajib
Android session-5-sajib
 
Lecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile DevicesLecture 10 Networking on Mobile Devices
Lecture 10 Networking on Mobile Devices
 
Java ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and ThreadsJava ME - 04 - Timer, Tasks and Threads
Java ME - 04 - Timer, Tasks and Threads
 
Mobile Device APIs
Mobile Device APIsMobile Device APIs
Mobile Device APIs
 
Android Networking
Android NetworkingAndroid Networking
Android Networking
 
Communication in android
Communication in androidCommunication in android
Communication in android
 
Manual redes - network programming with j2 me wireless devices
Manual   redes - network programming with j2 me wireless devicesManual   redes - network programming with j2 me wireless devices
Manual redes - network programming with j2 me wireless devices
 
Java adv
Java advJava adv
Java adv
 
Tomcat New Evolution
Tomcat New EvolutionTomcat New Evolution
Tomcat New Evolution
 

More from Andreas Jakl

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityAndreas Jakl
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAndreas Jakl
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndreas Jakl
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndreas Jakl
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndreas Jakl
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Andreas Jakl
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web TechnologiesAndreas Jakl
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreAndreas Jakl
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Andreas Jakl
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test AutomationAndreas Jakl
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Andreas Jakl
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneAndreas Jakl
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingAndreas Jakl
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartAndreas Jakl
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosAndreas Jakl
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentAndreas Jakl
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)Andreas Jakl
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt CommunicationAndreas Jakl
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and GraphicsAndreas Jakl
 

More from Andreas Jakl (20)

Create Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented RealityCreate Engaging Healthcare Experiences with Augmented Reality
Create Engaging Healthcare Experiences with Augmented Reality
 
AR / VR Interaction Development with Unity
AR / VR Interaction Development with UnityAR / VR Interaction Development with Unity
AR / VR Interaction Development with Unity
 
Android Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App ManagementAndroid Development with Kotlin, Part 3 - Code and App Management
Android Development with Kotlin, Part 3 - Code and App Management
 
Android Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSONAndroid Development with Kotlin, Part 2 - Internet Services and JSON
Android Development with Kotlin, Part 2 - Internet Services and JSON
 
Android Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - IntroductionAndroid Development with Kotlin, Part 1 - Introduction
Android Development with Kotlin, Part 1 - Introduction
 
Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)Android and NFC / NDEF (with Kotlin)
Android and NFC / NDEF (with Kotlin)
 
Basics of Web Technologies
Basics of Web TechnologiesBasics of Web Technologies
Basics of Web Technologies
 
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & MoreBluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
Bluetooth Beacons - Bluetooth 5, iBeacon, Eddystone, Arduino, Windows 10 & More
 
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
Which new scenarios are enabled by Windows 10 for NFC, Bluetooth LE & Beacons?
 
Mobile Test Automation
Mobile Test AutomationMobile Test Automation
Mobile Test Automation
 
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
Qt App Development - Cross-Platform Development for Android, iOS, Windows Pho...
 
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows PhoneWinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
WinJS, Apache Cordova & NFC - HTML5 apps for Android and Windows Phone
 
Nokia New Asha Platform Developer Training
Nokia New Asha Platform Developer TrainingNokia New Asha Platform Developer Training
Nokia New Asha Platform Developer Training
 
Windows Phone 8 NFC Quickstart
Windows Phone 8 NFC QuickstartWindows Phone 8 NFC Quickstart
Windows Phone 8 NFC Quickstart
 
Windows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App ScenariosWindows (Phone) 8 NFC App Scenarios
Windows (Phone) 8 NFC App Scenarios
 
Windows 8 Platform NFC Development
Windows 8 Platform NFC DevelopmentWindows 8 Platform NFC Development
Windows 8 Platform NFC Development
 
NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)NFC Development with Qt - v2.2.0 (5. November 2012)
NFC Development with Qt - v2.2.0 (5. November 2012)
 
06 - Qt Communication
06 - Qt Communication06 - Qt Communication
06 - Qt Communication
 
05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics05 - Qt External Interaction and Graphics
05 - Qt External Interaction and Graphics
 
04 - Qt Data
04 - Qt Data04 - Qt Data
04 - Qt Data
 

Recently uploaded

SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...CzechDreamin
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlPeter Udo Diehl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...Product School
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Product School
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024Stephanie Beckett
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutesconfluent
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...Product School
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Alison B. Lowndes
 

Recently uploaded (20)

SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 

Java ME - 07 - Generic Connection Framework, HTTP and Sockets

  • 1. Java™Platform, Micro Edition Part 7Generic Connection Framework, HTTP and Sockets v3.0 – 06 April 2009 1 Andreas Jakl, 2009
  • 2. Disclaimer These slides are provided free of charge at http://www.symbianresources.com and are used during Java ME courses at the University of Applied Sciences in Hagenberg, Austria at the Mobile Computing department ( http://www.fh-ooe.at/mc ) Respecting the copyright laws, you are allowed to use them: for your own, personal, non-commercial use in the academic environment In all other cases (e.g. for commercial training), please contact andreas.jakl@fh-hagenberg.at The correctness of the contents of these materials cannot be guaranteed. Andreas Jakl is not liable for incorrect information or damage that may arise from using the materials. This document contains copyright materials which are proprietary to Sun or various mobile device manufacturers, including Nokia, SonyEricsson and Motorola. Sun, Sun Microsystems, the Sun Logo and the Java™ Platform, Micro Edition are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. Andreas Jakl, 2009 2
  • 3. Contents Generic Connection Framework HTTP Connections Sockets Andreas Jakl, 2009 3
  • 4. Generic Connection Framework Java SE: 150+ classes and interfaces (java.io, java.net) Bytecode-size: java.net 200kB+ Consistency: Different objects for protocols CLDC: Generic Connection Framework (GCF) Unified API for various protocols Profilesdefine protocols (MIDP, additional packages) Mandatory for MIDP 2.0:Hypertext Transfer Protocol (HTTP)Hypertext Transfer Protocol over TLS/SSL (HTTPS) Today: GCF made its way into Java SE (JSR 197) Andreas Jakl, 2009 4
  • 5. Generic Connection Framework Hierarchy of interfaces and classes to: create connections (HTTP, datagrams, ...) perform I/O GCF used by optional packages Bluetooth, Files, SmartCards, Messaging, … … might look difficult at first, but is very easy to use! Andreas Jakl, 2009 5
  • 6. Connector Single Factory-class, creates any type of connection Examples: Connector.open(“http://www.mopius.com/”); Connector.open(“socket://realreplay.mopius.com:5412”); Connector.open(“file://data.txt”); Andreas Jakl, 2009 6 Connector.open(“protocol:address;parameters”);
  • 7. Connector – Protocols Protocol is chosen automatically, based on URL GCF searches for class that implements protocol Success: Returns class that implements Connection-interface Failure: ConnectionNotFoundException HTTP is supported for sure, Sockets might be unavailable on phone / through operator Andreas Jakl, 2009 7 Example: HttpConnection con = (HttpConnection) Connector.open (“http://www.mopius.com/”);
  • 8. Connect and Transfer Short example for sockets (omits error handling): Andreas Jakl, 2009 8 // Open the connection to a URL SocketConnection con = (SocketConnection) Connector.open(“socket://127.0.0.1:5000”); // Send request DataOutputStream dos = con.openDataOutputStream(); dos.writeShort(12); dos.writeUTF(“Hello World”); dos.close(); // Receive answer DataInputStreamdis = con.openDataInputStream(); short msgId = dis.readShort(); dis.close(); // Cleanup con.close();
  • 9. GCF – High Level Andreas Jakl, 2009 9 Generic way of handlingall communication andall protocols. Generic factory class, common interface Wait for incoming stream connections Stream-based I/O Packet-based I/O GCF (without additional packages like Bluetooth)supports three types of communication Additional content-specific information (data length, content type, data encoding, …) More comfortablefunctions for protocolslike HTTP are available.
  • 10. GCF – Basic Class Diagram Andreas Jakl, 2009 10 Connection Connector ConnectionNotFoundException Generic factory class, common interface creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Other subtypes… Wait for incoming stream connections Stream-based I/O Packet-based I/O creates Datagram StreamConnection ContentConnection Other subtypes… Other subtypes… Additional content-specific information (data length, content type, data encoding, …) Other subtypes… CLDC
  • 11. GCF – Basic Class Diagram Andreas Jakl, 2009 11 Connection Connector ConnectionNotFoundException creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Other subtypes… creates Datagram StreamConnection ContentConnection Other subtypes… Other subtypes… Other subtypes… CLDC
  • 12. GCF – MIDP Class Diagram Andreas Jakl, 2009 12 Connection Connector ConnectionNotFoundException creates throws DatagramConnection InputConnection OutputConnection StreamConnectionNotifier Bluetooth Messaging creates Datagram StreamConnection UDPDatagramConnection CommConnection SocketConnection ContentConnection ServerSocketConnection FileConnection HttpConnection SecureConnection HttpsConnection MIDP 2.0 CLDC Optional JSRs
  • 13. URL Uniform Resource Locator (URL) Identify connection type and endpoint Andreas Jakl, 2009 13 scheme://user:password@host:port/url-path;parameters
  • 14. URL – Schemes Some of GCF connection types: Andreas Jakl, 2009 14 ... you can only be sure that HTTP(S) is available on a device!
  • 15. public void commandAction (Command command, Displayable displayable) { if (command == iCmdConnect) { con = (HttpConnection) Connector.open("http://www.mopius.com/images/mopius.png"); } } Asynchronous Connection Andreas Jakl, 2009 15 Establishing a connection in the command handling function leads to a deadlock!  The user can no longer select “Yes” or “No”. Notification message provided by WTK (console):
  • 16. Asynchronous Connection Solution: Start own thread for networking code! Andreas Jakl, 2009 16 public class MyClass extends MIDlet implements CommandListener, Runnable { // … // Process the command to connect to the network public void commandAction(Command command, Displayable displayable) { if (command == cmdConnectToWeb) { // Start connection in extra thread  commandAction-function is not blocked new Thread(this).start(); } } // Connect to the network public void run() { // … HttpConnection con = (HttpConnection)Connector.open(url); // … } }
  • 17. Error Handling Connection should always be closed ( Exception!) Andreas Jakl, 2009 17 // Define those two variables outside the try-block, so that they are known in the finally-block! SocketConnection con = null; DataInputStream is = null; try { con = (SocketConnection)Connector.open(url); // Open the connection to the requested URL // … (optional) define the request package and/or send data … is = con.openDataInputStream(); // Read from the connection // … read from the input stream to process data … } catch (IOException ex) { } finally { try { if (is != null) // Here we make sure that everything that might still be open is closed! is.close(); if (con != null) con.close(); } catch (IOException ex) { // This error can usually be ignored, as something else already went wrong… } }
  • 18. HyperText Transfer Protocol Information about the Andreas Jakl, 2009 18
  • 19. HTTP HTTP = Hypertext Transfer Protocol Request/Response-protocol Andreas Jakl, 2009 19 Client submitsRequestHeader, Body, … Server GPRS, UMTS, WLAN, … CallbackResponseHeader, Body, …
  • 20. HTTP in JavaME Similar to the logical structure: Open a connection Prepare the request message Send request + body (optional, POST only) Retrieve response Close connection (can’t be reused!) Andreas Jakl, 2009 20
  • 21. HTTP Messages Andreas Jakl, 2009 21 Server
  • 22. Request Method 3 request methods supported: Andreas Jakl, 2009 22
  • 23. HTTP Get Andreas Jakl, 2009 23 JavaME-code: String url = "http://www.mopius.com/test.php?user=me&pwd=xxx"; HttpConnection con = (HttpConnection)Connector.open(url); con.setRequestMethod(HttpConnection.GET); // Define method as GET conn.setRequestProperty("User-Agent", "Mozilla/4.0"); intrc = con.getResponseCode(); // Request is sent with first read-function // No write required! HTTP-Request received by the web-server: GET /test.php?user=me&pwd=xxx HTTP/1.1 Host: www.mopius.com User-Agent: Mozilla/4.0
  • 24. HTTP Post – Form Andreas Jakl, 2009 24 JavaME-code: String url = "http://www.mopius.com/test.php"; String data = "user=me&pwd=xxx"; // Data to send, without & // Special characters have to be URL-encoded manually (e.g. " " -> "%20") HttpConnection con = (HttpConnection)Connector.open(url); con.setRequestMethod(HttpConnection.POST); // Define method as POST con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); con.setRequestProperty("User-Agent", "Mozilla/4.0"); con.setRequestProperty("Content-Length", Integer.toString(data.length())); OutputStreamos = con.openOutputStream(); os.write(data.getBytes()); os.close();// Request is sent when output-stream is closed intrc = con.getResponseCode(); HTTP-Request received by the web-server: POST /test.php HTTP/1.1 Host: www.mopius.com User-Agent: Mozilla/4.0 Content-Length: 15 Content-Type: application/x-www-form-urlencoded user=me&pwd=xxx
  • 25. HTTP Post – Raw Data For raw client-server communication: Set content type Create byte array, e.g. using DataOutputStream Andreas Jakl, 2009 25 con.setRequestProperty("Content-Type", "application/octet-stream"); DataOutputStream dos = new DataOutputStream( con.openOutputStream() ); dos.writeBoolean(true); dos.writeUTF("Hello World"); dos.close();
  • 26. Server Response Status line contains numeric value + text Query response code: Andreas Jakl, 2009 26 intrc = con.getResponseCode(); Overview: HTTP status categories Most important status codes and the respective constants in HttpConnection
  • 27. Retrieving a HTTP Response Simple version: (creates an image based on stream) Next slide: More complex version Reads response differently, depending on if the length is known Andreas Jakl, 2009 27 // ... send request ... intrc = con.getResponseCode(); // Retrieve HTTP response code if (rc == HttpConnection.HTTP_OK) { // Response in most cases only available for OK is = con.openDataInputStream(); // Get the data input stream Image img = Image.createImage(is); // Read image }
  • 28. Retrieving a HTTP Response Andreas Jakl, 2009 28 // ... send request ... intrc = con.getResponseCode(); // Retrieve HTTP response code if (rc == HttpConnection.HTTP_OK) { // Response in most cases only available for OK is = con.openDataInputStream(); // Get the data input stream int length = (int)con.getLength(); // Get length of the response - int is enough byte data[]; if (length > 0) { // If the server set the content length... data = new byte[length]; // Do a direct, more efficient read using a fixed byte array inttotalReadBytes = 0; // is.read() might not read everything at once while (totalReadBytes < length) { //  continue reading until expected length is received intcurReadBytes = is.read(data, totalReadBytes, length - totalReadBytes); if (curReadBytes == -1) break; // Reached the end before the expected length? totalReadBytes += curReadBytes; } } else { // If the length is unknown, however, use a dynamic stream ByteArrayOutputStreambos = new ByteArrayOutputStream(); intch; while ((ch = is.read()) != -1) { // Read each byte until a the end is reached bos.write(ch); // Append the new character to the byte array output stream } bos.flush(); data = bos.toByteArray(); // Create a byte array based on the stream bos.close(); } }
  • 29. Sockets Low-Level Communication Andreas Jakl, 2009 29
  • 30. Socket Communication Multiplayer games / applications – HTTP? Request / response might not be useful Large overhead through headers Sockets: Server listens at specific port Client connects to server Bidirectional communication possible Andreas Jakl, 2009 30
  • 31. Streams / Datagrams Stream socket: Uses TCP (Connection-oriented protocol) Open – send/receive ... – Close Delivery & order of data are guaranteed Datagram socket: Uses UDP (Record-oriented system) Datagram = chunk of data, no stream Delivery not guaranteed Faster than TCP Mobile phone: Performance issues in any case (network speed)! Andreas Jakl, 2009 31
  • 32. Sockets and Java ME Similar to HTTP: Writing and Reading: Andreas Jakl, 2009 32 TCP-Connection: SocketConnection con = (SocketConnection) Connector.open(“socket://127.0.0.1:5000”); UDP-Connection: UDPDatagramConnection con = (UDPDatagramConnection)Connector.open(“datagram://127.0.0.1:5000”); InputStream is = con.openInputStream(); OutputStreamos = con.openOutputStream(); // … write and read to/from the streams … is.close(); os.close(); con.close();
  • 33. Thanks for your attention That’s it! Andreas Jakl, 2009 33