client-server interactions in mobile applications

13
Client-server interactions in Mobile Applications

Post on 22-Dec-2015

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Client-server interactions in Mobile Applications

Client-server interactionsin Mobile Applications

Page 2: Client-server interactions in Mobile Applications

2

Socket programming with TCP

Example client-server app:1) client reads line from standard

input (inFromUser stream) , sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to uppercase,

sends back to client4) client reads, prints modified line

from socket (inFromServer stream) ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Page 3: Client-server interactions in Mobile Applications

3

Client/server socket interaction: TCP

wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()

create socket,port=x, forincoming request:welcomeSocket =

ServerSocket()

create socket,connect to hostid, port=xclientSocket =

Socket()

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

Page 4: Client-server interactions in Mobile Applications

XML-RPC

remote procedure call protocol, created in 1998

specification and a set of implementations, allowing procedure calls over the Internet

calls are transported using HTTP, and encoded in XML.

simple security model, can authenticate through HTTP/HTTPS

Page 5: Client-server interactions in Mobile Applications

Allows one method of serialization Still in use, although newer technologies exist;

JSON-RPC, SOAP and others. www.xmlrpc.com

Page 6: Client-server interactions in Mobile Applications

Disadvantages

XML can be slow and cumbersome in transporting and processing messages

Calls can be made with plain XML instead; XML-RPC doesn't add any additional value

Page 7: Client-server interactions in Mobile Applications

Implementations:Client:Android XML-RPC Thin, but complete XML-RPC

library http://code.google.com/p/

android-xmlrpc/

Server:Apache XML-RPC Servlet http://ws.apache.org/

xmlrpc/server.html

Page 8: Client-server interactions in Mobile Applications

SOAP

• Simple Object Access Protol: is a protocol specification for exchanging structured information in the implementation of Web Services in computer networks.

Page 9: Client-server interactions in Mobile Applications

SOAP

Page 10: Client-server interactions in Mobile Applications

SOAP

• Advantage– Allow for the use of different transport protocols (HTTP as a transport

protocol, but other protocols such as JMS and SMTP are also usable)– Since the SOAP model tunnels fine in the HTTP get/response model, it

can tunnel easily over existing firewalls and proxies.– Can extend the existing infrastructure.

• Disadvantage– Since SOAP bases on XML format, it require lots of resource for

parsing and processing XML file (especially for large XML file).– SOAP is very verbose, and contains lots of overhead.

Not the best choice for data exchange with mobile devices.

Page 11: Client-server interactions in Mobile Applications

JSON

JavaScript Object Notation – language independent specification of interchanging data in human-readable format.

•In contrast with XML-RPC and SOAP it allows for bidirectional communication between client and server (like peers) and for multiple calls.•Data introduced in key:value pair format.•More economical than XML in terms of data size, but has less readability.•Android has JSONArray, JSONObject, JSONStringer and JSONTokener objects for parsing this format.

Page 12: Client-server interactions in Mobile Applications

Protocol Buffers

Protocol Buffers– language independent data-serialization format developed by Google. This protocol is usually applied in server-to-server interactions.

•Is significant faster and smaller than XML.•Type of messages is defined in .proto files.•Message is small logical record of a pairs of names and values.•Transmitted information is encoded into binary format.•Google provide necessary tools for binding this protocol with C++, Java and Python.

Page 13: Client-server interactions in Mobile Applications

Comparison of protocols

“Using Internet data in Android applications” by Michael Galpin, IBM 2010,

http://www.ibm.com/developerworks/opensource/library/x-dataAndroid/index.html