Server - Client Communication

19
Server - Client Communication 8.4.2013

description

Server - Client Communication. 8.4.2013. Getting data from server. Required permissions. To access the Internet your application requires android.permission.INTERNET To check the network state your application requires android.permission.ACCESS_NETWORK_STATE. Network on Android. - PowerPoint PPT Presentation

Transcript of Server - Client Communication

Page 1: Server - Client Communication

Server - Client Communication

8.4.2013

Page 2: Server - Client Communication

Getting data from server

Page 3: Server - Client Communication

Required permissions

To access the Internet your application requires android.permission.INTERNET 

To check the network state your application requires android.permission.ACCESS_NETWORK_STATE 

Page 4: Server - Client Communication

Network on Android

Network java.net package contains HttpURLConnection class includingApache HttpClient library

Page 5: Server - Client Communication

Apache HttpClient library

A client-side HTTP transport library

Purpose – to transmit – receive HTTP messages– server-client communication

Page 6: Server - Client Communication

Apache HttpClient library

User Provide a request object

Http Client -send request to the target server -return a corresponding response object- or throw an exception if execution was unsuccessful

- one or several HTTP request / HTTP response

Page 7: Server - Client Communication

Introduction to JSON

JavaScript Object Notation

Independent data exchange format Limited to text and numeric values

Binary values are not supported

Page 8: Server - Client Communication

JSON

An JSON object is a set of key (string) / value (string/numerical) pairs which starts with "{" and ends with "}"

Page 9: Server - Client Communication

JSONAndroid includes thejson.org libraries

Writing JSON is very simple

Just create the JSONObject

Use the toString() method

Work easily with JSON files

Page 10: Server - Client Communication

Steps

Send Request to Server

Create JSON array

Getting response from server

Display Response in String format

Request Object from user

Page 11: Server - Client Communication

JSON array

Request Object

1. Send request to server

2. Request Object from user

3. Creat JSON array

4. Getting response from server

Flow

Page 12: Server - Client Communication

Parsing JSON

Page 13: Server - Client Communication

Result data from server

Page 14: Server - Client Communication

Display Image from server

Page 15: Server - Client Communication

Display Image from link

Convert string to URI

Send Request to server and Receive response

HttpEntity , BufferedHttpEntity:

Bitmap factory

Display Image

Link (String)

Page 16: Server - Client Communication

Display image from link

2. Send Request to server and Receive response

1. Convert string to URI

Page 17: Server - Client Communication

3. HttpEntity: Get http message in streamed form

4. BufferedHttpEntity: Used to save content of entity

5. Bitmap factory : Creates Bitmap objects from various sources, including files, streams, and byte-arrays

Display image from link

Page 18: Server - Client Communication

.

Page 19: Server - Client Communication

Result