Professional Documents
Culture Documents
MAD Ch5
MAD Ch5
Services
Chapter 5
Contents
➔ Networking basics
➔ Determining network status
➔ Communicating with a server socket
➔ Working with web services
1-Networking basics
● The short example shows that you can get a handle to the ConnectivityManager
through the context’s getSystemService() method by passing the
CONNECTIVITY_SERVICE constant.
● When you have the manager, you can obtain network information via the
NetworkInfo object.
● The toString() method of the NetworkInfo object returns the output.
Checking the network status
● A server socket is a stream that you can read or write raw bytes to, at a specified IP
address and port.
● You can deal with data and not worry about media types, packet sizes, and so on.
Description of the code
● The above java code extends Thread and implements the run method
● Uses ServerSocket to listen for a client connection on a specific port
● Uses a BufferedReader’s readLine() to get input from client, if the input is EXIT it
terminates the Server, otherwise, it sends the input back to the client using
BufferedWriter’s write()
● Run the code separately as a java code. (use cmd )
The Client Side
The Client code description
● Creates a client side Socket with the IP address and Port number of the server
Socket cl=new Socket(ip,port )
● Establishes BufferedReader & BufferedWriter to read data from server & write data
to server.
BufferedWriter wr=new BufferedWriter(new OutputStreamWriter
( cl.getOutputStream() ) );
● Finally, writes EXIT message to server, to end the socket connection
wr.write(“EXIT”,0,5);
Working with web services
● Web services are XML-based information exchange systems that use the
Internet for direct application-to-application interaction.
● They’re a means to call a remote method or operation that’s not tied to a specific
platform/vendor and get a result.
● POX, REST, and SOAP are the most common web services
● POX basically exposes chunks of XML over the wire, usually over HTTP.
● REST uses the concept of resources to define data and then manipulates them with
different HTTP methods using a URL-style
● SOAP is the most formal of them all, imposing strict rules about types of data,
transport mechanisms, and security.
The End