android_overview.pdf

(555 KB) Pobierz
Android Overview
Android Overview
Dongsu Han
1
391434700.003.png 391434700.004.png
Outline
Java network programming overview
Android Overview
Android Emulator Overview
Project Overview
Getting Started
2
391434700.005.png
Java Network Programming
Java.net.* programming model
Blocking model, you wait until work is done, maybe
forever
One thread required per connection
Socket exposes input and output stream
Java.nio.* programming model
Introduced in Java 1.4, non-blocking IO
New Interface: SocketChannel (in java.nio.channels)
Reading/writing via Buffer objects rather than
input/output streams
Select() implemented
3
391434700.006.png
Java.net.* Socket API
Part of the java.net package
import java.net.*;
Provides two classes of sockets for TCP
Socket : client side of socket
ServerSocket : server side of socket
Provides one socket type for UDP
DatagramSocket
4
391434700.001.png
Java.net.Socket
Making a connection
Socket s = new Socket(“hostname”, port);
The constructor not only creates a socket, but
makes a TCP connection.
Socket exposes input and output stream.
s.getOutputStream()
s.getInputStream()
Most of the time you'll chain the input/output
stream to some other input/output stream or
reader object to more easily handle the data.
5
391434700.002.png
Zgłoś jeśli naruszono regulamin