Académique Documents
Professionnel Documents
Culture Documents
programming
Netzprogrammierung
(Algorithmen und Programmierung V)
Architectural patterns
Security
Vertical distribution Horizontal distribution model
Multi-tier Thin/Fat Client
Architectural patterns
Security
Vertical distribution Horizontal distribution model
Multi-tier Thin/Fat Client
Multicast communication
Layer n
Layer 2
Layer 1
Application
Presentation
Session
Transport
Network
Data link
Physical
Application-layer
message
Presentation
header
Session
header
Transport
header
Network
header
Internet
IP datagrams
Network interface
Network-specific frames
Underlying network
• Example
w3c = InetAddress.getByName(“www.w3c.org”);
me = InetAddress.getByName(“localhost”);
System.out.println(InetAddress.getByName ("localhost"));
localhost/127.0.0.1
System.out.println(InetAddress.getLocalHost());
lounge.mi.fu-berlin.de/160.45.42.83
http://download.oracle.com/javase/8/docs/api/java/net/InetAddress.html
Barry Linnert, linnert@inf.fu-berlin.de, Netzprogrammierung WS 2015/16 13
API for Internet protocols
Applications, services
Middleware
Underlying inter-process communication primitives:
layers
Sockets, message passing, multicast support
message
client server
other ports
Internet address = 138.37.94.248 Internet address = 138.37.88.249
Timeouts can be set, in order to avoid that the receive operation waits
indefinitely
Failures
• Omission failures: messages maybe dropped occasionally
because of checksum error or no buffer space is available at
source/destination
• Ordering: Messages can sometimes be delivered out of order
Example 2: VOIP
• No reason to re-transmit packets with bad speech data
• Speech data must be processed (play time) at the same rate as it is sent -
there is no time to retransmit packets with errors
DatagramPacket
• Constructor that makes an instance out of an array of bytes comprising a
message
• Constructor for use when receiving a message, message can be retrieved
by the method getData
DatagramSocket
• Constructor that takes port number as argument for use by processes
• No-argument constructor for choosing a free local port
clientSocket.close();
}
}
Barry Linnert, linnert@inf.fu-berlin.de, Netzprogrammierung WS 2015/16 28
Example: Java server (UDP)
import java.io.*;
import java.net.*;
class UDPServer {
public static void main(String args []) throws Exception
{
sendData = capitalizedSentence.getBytes();
DatagramPacket sendPacket =
Create datagram new DatagramPacket(sendData, sendData.length,
to send to client IPAddress, port);
TCP supports flow control that means if the writer is too fast for the reader,
then the writer is blocked until the reader consumed sufficient data.
Message identifiers are used by each IP packet. The recipient can therefore
detect and reject duplicates or can reorder message if needed.
http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
1a)
http client initiates TCP connection to
http server (process) at 1b)
www.inf.fu-berlin.de; http server at host
Port 80 is default for http server www.inf.fu-berlin.de waiting for TCP
connection at port 80;
“accepts” connection, notifying client
time
2)
http client sends http request
message (containing URL) into TCP
connection socket
3)
http server receives request
message, forms response message
containing requested object
(someDepartment/home.index),
sends message into socket
Barry Linnert, linnert@inf.fu-berlin.de, Netzprogrammierung WS 2015/16 36
The HTTP protocol (cont.)
4)
http server closes TCP connection
5)
http client receives response
time
6)
steps 1-5 repeated for each jpeg
objects
ServerSocket
• Class is intended to be used by server to create a socket at a
server port for listening for connect requests from clients.
Socket
• Class is for use by a pair of processes with a connection
• The client uses a constructor to create a socket, specifying
the DNS hostname and port of a server
class TCPClient {
String sentence;
String modifiedSentence;
BufferedReader inFromServer =
Create input stream new BufferedReader(new InputStreamReader
attached to socket (clientSocket.getInputStream ()));
sentence = inFromUser.readLine();
Send line to server outToServer.writeBytes(sentence + '\n');
clientSocket.close();
}
}
Barry Linnert, linnert@inf.fu-berlin.de, Netzprogrammierung WS 2015/16 41
Example: Java server (TCP)
import java.io.*;
import java.net.*;
class TCPServer {
public static void main(String argv []) throws Exception {
String clientSentence;
String capitalizedSentence;
Read in line
from socket clientSentence = inFromClient.readLine();
Marshalling
The process of taking a collection of data
items and assembling them into a form
suitable for transmission in a message
http://www.breti.org/tech/files/b400feb80f01f69e5cafca5160be5d65-67.html
Unmarshalling
Is the process of disassembling them on arrival into an equivalent
representation at the destination
XML
• Defines a textual format for representing structured data
Available data-types
• Primitive data-type
• int, float, bool, string, raw-
bytes
• Enumerated data-type
• Nested Message
• Allows structuring data into an
hierarchy
Barry Linnert, linnert@inf.fu-berlin.de, Netzprogrammierung WS 2015/16 49
Protocol Buffer Language (cont)
Field-types can be:
• Required fields
• Optional fields
• Repeated fields
• Dynamically sized array
Encoding-value
• A unique number (=1,=2,…)
represents a tag that a particular
field has in the binary encoding of the
message
http://www.breti.org/tech/files/b400feb80f01f69e5cafca5160be5d65-67.html
Connectionless 1:1
UDP
Connectionless 1:n
Multicast
Please note: send, receive, ... are inherited from class DatagramSocket
Architectural patterns
Security
Vertical distribution Horizontal distribution model
Multi-tier Thin/Fat Client