SlideShare une entreprise Scribd logo
1  sur  42
School of Systems Engineering
BSc Computer Science - “Java” (SE2JA11)

Network Protocols in Java
Dr. Giuseppe Di Fatta
- Associate Professor of Computer Science
Web: http://www.personal.reading.ac.uk/~sis06gd/
Email: G.DiFatta@reading.ac.uk

- Director of the MSc Advanced Computer Science
http://www.reading.ac.uk/sse/pg-taught/sse-mscadvancedcomputerscience.aspx

These lecture slides are available at:
http://www.personal.reading.ac.uk/~sis06gd/resources.html
Outline
 Introduction to Networking
• Network protocols
• Client-server network applications

 Java Socket programming using TCP and UDP
 Simple Mail Transfer Protocol (SMTP)
 Code examples:
• How to send an email in Java
• How to implement a simple FTP client in Java

Java, Dr. Giuseppe Di Fatta, 2007-2013

2
What’s a protocol?
human protocols:
• “what’s the time?”
• “I have a question”
• introductions
… specific msgs sent
… specific actions taken
when msgs received,
or other events

network protocols:
• machines rather than
humans
• all communication
activity in Internet
governed by protocols
A protocol defines:
• format and order of messages
sent and received among
network entities
• actions taken on message
transmission, receipt

Java, Dr. Giuseppe Di Fatta, 2007-2013

3
What’s a protocol?
a human protocol and a computer network protocol:

Hi

TCP connection
req

Hi

TCP connection
response

Got the
time?

Get http://www.google.com/

2:00

<file>
time

Java, Dr. Giuseppe Di Fatta, 2007-2013

4
Internet protocol stack
• application: supporting network
applications
– FTP, SMTP, STTP

• transport: host-host data transfer
– TCP, UDP

• network: routing of datagrams from
source to destination
– IP, routing protocols

• link: data transfer between neighboring
network elements
– PPP, Ethernet

application

transport
network

link
physical

• physical: bits “on the wire”

Java, Dr. Giuseppe Di Fatta, 2007-2013

5
Network applications: some jargon
Process: program running
user agent: interfaces with
within a host.
user “above” and network
• within same host, two
“below”.
processes communicate
• implements user interface
using interprocess
& application-level
communication (defined by
protocol
OS).
– Web: browser
• processes running in
– E-mail: mail reader
different hosts
– streaming audio/video:
communicate with an
media player
application-layer protocol

Java, Dr. Giuseppe Di Fatta, 2007-2013

6
Applications and application-layer protocols
Application: communicating,
distributed processes
– e.g., e-mail, Web, P2P file
sharing, instant messaging
– running in end systems (hosts)
– exchange messages to
implement application

application
transport
network
data link
physical

Application-layer protocols
– one “piece” of an app
– define messages exchanged by
apps and actions taken
– use communication services
provided by lower layer
protocols (TCP, UDP)

application
transport
network
data link
physical

Java, Dr. Giuseppe Di Fatta, 2007-2013

application
transport
network
data link
physical

7
Application-Layer Protocol
A protocol defines:
• Types of messages
exchanged, e.g., request &
response messages
• Syntax of message types:
what fields in messages & how
fields are delineated
• Semantics of the fields, i.e.,
meaning of information in
fields
• Rules for when and how
processes send & respond to
messages

Public-domain protocols:
• standardised by IETF
• allow for interoperability
• e.g., HTTP, SMTP, FTP
Example of P2P protocols:
• BitTorrent

Example of some proprietary
P2P protocols:
• KaZaA
• Skype

Java, Dr. Giuseppe Di Fatta, 2007-2013

8
ARPANET-INTERNET Transition
• The Internet was born on January 1st, 1983: when
ARPANET changed from NCP to the TCP/IP protocol suite.
–

–

Flag day: a change which requires a complete restart or conversion of a relevant
software component or data. The change is large and expensive; reversing the change
is difficult or impossible.
“The goal is to make a complete switch over from the NCP to IP/TCP by 1 January
1983.” (Jon Postel, NCP/TCP Transition Plan, RFC 801)

Bob Kahn and Vint Cerf
- fathers of the Internet: inventors of the TCP/IP protocol suite

Java, Dr. Giuseppe Di Fatta, 2007-2013

9
IETF
The Internet Engineering Task Force (IETF) is a loosely self-organized group
of people who contribute to the engineering and evolution of Internet
technologies. The IETF in no way "runs the Internet“.

IETF quotes (believes)


Robert Kahn (interview, 2002):
People don't think of the Internet as a logical architecture. They think of it as what
AOL does. The Internet is an architectural philosophy, rather than a technology.



David Clark (1992-07-16, 24th IETF meeting):
We reject: kings, presidents and voting.
We believe in: rough consensus and running code.



Jon Postel (RFC 793 - September 1981) - Robustness Principle:
TCP implementations will follow a general principle of robustness:
be conservative in what you do, be liberal in what you accept from
others.
Jon Postel (1943-1998): see RFC 2468, October 1998
Java, Dr. Giuseppe Di Fatta, 2007-2013

10
Client-Server Paradigm
Typical network app has two
pieces: client and server

Client:
• initiates contact with server
(“speaks first”)
• typically requests service from
server,
• Web: client implemented in
browser; e-mail: in mail reader

application
transport
network
data link
physical

request

Server:
• provides requested service to client
• e.g., Web server sends requested Web
page, mail server delivers e-mail
Java, Dr. Giuseppe Di Fatta, 2007-2013

reply
application
transport
network
data link
physical

11
Addressing Hosts and Processes
• For a process to receive
messages, it must have an
identifier
• Every host has a unique 32bit IP address
• Q: does the IP address of
the host on which the
process runs suffice for
identifying the process?
• Answer: No, many
processes can be running
on same host

• Identifier includes both the
IP address and port
numbers associated with
the process on the host.
• Example port numbers:
– HTTP server: 80
– Mail server: 25

Java, Dr. Giuseppe Di Fatta, 2007-2013

12
IP Addresses
Current world population:
7 billion

IP v4 addresses: 232 = 4 billion
IP v6 addresses: 2128
Java, Dr. Giuseppe Di Fatta, 2007-2013

13
Processes communicating across network
• process sends/receives
messages to/from its socket
• socket analogous to door
– sending process shoves
message out door
– sending process assumes
transport infrastructure on
other side of door which brings
message to socket at receiving
process

host or
server

host or
server

process

controlled by
app developer

process
socket

socket
TCP with
buffers,
variables

Internet

TCP with
buffers,
variables

controlled
by OS

• API: (1) choice of transport protocol; (2) ability to fix a few parameters
Java, Dr. Giuseppe Di Fatta, 2007-2013

14
Internet transport protocols services
TCP service:

UDP service:

• connection-oriented: setup
required between client and
server processes
• reliable transport between
sending and receiving process
• flow control: sender won’t
overwhelm receiver
• congestion control: throttle
sender when network
overloaded
• does not providing: timing,
minimum bandwidth
guarantees

• unreliable data transfer
between sending and
receiving process
• does not provide:
connection setup, reliability,
flow control, congestion
control, timing, or
bandwidth guarantee
Q: why bother? Why is there a
UDP?

Java, Dr. Giuseppe Di Fatta, 2007-2013

15
Internet Applications

Application
e-mail
remote terminal access
Web
file transfer
streaming multimedia

Internet telephony

Application
layer protocol

Underlying
transport protocol

SMTP [RFC 2821]
Telnet [RFC 854]
HTTP [RFC 2616]
FTP [RFC 959]
proprietary

TCP
TCP
TCP
TCP
TCP or UDP

proprietary

typically UDP

Java, Dr. Giuseppe Di Fatta, 2007-2013

16
Socket programming
Goal: learn how to build client/server application that
communicate using sockets.
Socket API
• introduced in BSD4.1 UNIX, 1981
• explicitly created, used, released by
applications
• client/server paradigm
• two types of transport service via socket
API:
– unreliable datagram (UDP)
– reliable, byte stream-oriented (TCP)

socket
a host-local, application-created,
OS-controlled
interface
(a
“door”) into which application
process can both send and
receive
messages
to/from
another application process.

Java, Dr. Giuseppe Di Fatta, 2007-2013

17
Socket-programming using TCP
Socket: a door between application process and
end-end-transport protocol (UCP or TCP)
TCP service: reliable transfer of bytes from one
process to another
controlled by
application
developer
controlled by
operating
system

process

process
socket
TCP with
buffers,
variables

host or
server

internet

socket
TCP with
buffers,
variables

controlled by
application
developer
controlled by
operating
system

host or
server
Java, Dr. Giuseppe Di Fatta, 2007-2013

18
Socket programming with TCP
Client must contact server
• server process must first be
running
• server must have created
socket (door) that welcomes
client’s contact
Client contacts server by:
• creating client-local TCP
socket
• specifying IP address, port
number of server process
• When client creates socket:
client TCP establishes
connection to server TCP

• When contacted by client,
server TCP creates new
socket for server process to
communicate with client
– allows server to talk with
multiple clients
– source port numbers used
to distinguish clients
application viewpoint

TCP provides reliable, in-order
transfer of bytes (“pipe”)
between client and server

Java, Dr. Giuseppe Di Fatta, 2007-2013

19
Stream jargon
stream of bytes

file

stream of bytes

stream of bytes

Process

• A stream is a sequence
of characters that flow
into or out of a process.
• An input stream is
attached to some input
source for the process,
eg, keyboard or socket.
• An output stream is
attached to an output
source, eg, monitor or
socket.

Input streams

Internet

Output streams
stream of bytes

file

stream of bytes

stream of bytes

Java, Dr. Giuseppe Di Fatta, 2007-2013

Internet
20
Socket programming with TCP

Process
Client
Process

output
stream

monitor

inFromUser

input
stream

outToServer

1) client reads line from standard
input (inFromUser stream) ,
sends to server via socket
(outToServer stream)
2) server reads line from socket
3) server converts line to
uppercase, sends back to client
4) client reads, prints modified line
from socket (inFromServer
stream)

keyboard

inFromServer

Example client-server app:

input
stream

client TCP
clientSocket
socket
to network

Java, Dr. Giuseppe Di Fatta, 2007-2013

TCP
socket

from network

21
Client/server socket interaction: TCP
2

4

Server

Client
TCP connection

3
-1

1

create socket for
incoming request:
welcomeSocket =
ServerSocket()

TCP connection setup

wait for incoming
connection request
connectionSocket =
welcomeSocket.accept()
read request from
connectionSocket
write reply to
connectionSocket
close
connectionSocket

2

3

create socket to server

0

clientSocket =
Socket()
reliable fullduplex channel

1

send request using
clientSocket

read reply from
4 clientSocket
close
clientSocket
Java, Dr. Giuseppe Di Fatta, 2007-2013

22
Example: Java TCP client (1)
public static void main(String argv[])
{
String sentence;
String modifiedSentence;
Create
input stream
Create
client socket,
connect to server
Create
output stream
attached to socket

BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
Socket clientSocket = new Socket("hostname", 6789);
DataOutputStream outToServer =
new DataOutputStream(clientSocket.getOutputStream());

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

23
Example: Java TCP client (2)
Create
input stream
attached to socket

BufferedReader inFromServer =
new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));

sentence = inFromUser.readLine();
Send line
to server

outToServer.writeBytes(sentence + 'n');

Read line
from server

modifiedSentence = inFromServer.readLine();

System.out.println("FROM SERVER: " + modifiedSentence);
clientSocket.close();
}

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

24
Example: Java TCP server (1)

Create
welcoming socket
at port 6789
Wait, on welcoming
socket for contact
by client
Create input
stream, attached
to socket

public static void main(String argv[])
{
String clientSentence;
String capitalizedSentence;

ServerSocket welcomeSocket = new ServerSocket(6789);
while(true) {
Socket connectionSocket = welcomeSocket.accept();

BufferedReader inFromClient =
new BufferedReader(new
InputStreamReader(connectionSocket.getInputStream()));

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

25
Example: Java TCP server (2)
Create output
stream, attached
to socket

DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());

Read in line
from socket

clientSentence = inFromClient.readLine();
capitalizedSentence = clientSentence.toUpperCase() + 'n';

Write out line
to socket

outToClient.writeBytes(capitalizedSentence);

}
}
End of while loop,
loop back and wait for
another client connection

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

26
Socket programming with UDP
UDP: no “connection” between
client and server
• no handshaking
• sender explicitly attaches IP
address and port of
destination to each packet
• server must extract IP
address, port of sender from
received packet

application viewpoint

UDP provides unreliable transfer
of groups of bytes (“datagrams”)
between client and server

UDP: transmitted data may be
received out of order, or lost

Java, Dr. Giuseppe Di Fatta, 2007-2013

27
Client/server socket interaction: UDP
Server (running on hostid)
create socket,
port=x, for
incoming request:
serverSocket =
DatagramSocket()

read request from
serverSocket
write reply to
serverSocket
specifying client
host address,
port number

Client
create socket,
clientSocket =
DatagramSocket()
Create, address (hostid, port=x,
send datagram request
using clientSocket

read reply from
clientSocket
close
clientSocket

Java, Dr. Giuseppe Di Fatta, 2007-2013

28
Example: Java client (UDP)

input
stream

Client
process

monitor

inFromUser

keyboard

Process

Input: receives

packet (TCP
received “byte
stream”)

UDP
packet

receivePacket

packet (TCP sent
“byte stream”)

sendPacket

Output: sends

client UDP
clientSocket
socket
to network

UDP
packet

UDP
socket

from network

Java, Dr. Giuseppe Di Fatta, 2007-2013

29
Example: Java UDP client (1)

Create
input stream
Create
client socket
Translate
hostname to IP
address using DNS

public static void main(String args[])
{
BufferedReader inFromUser =
new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("hostname");
byte[] sendData = new byte[1024];
byte[] receiveData = new byte[1024];

String sentence = inFromUser.readLine();
sendData = sentence.getBytes();

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

30
Example: Java UDP client (2)
Create datagram
with data-to-send,
length, IP addr, port

DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, 9876);

Send datagram
to server

clientSocket.send(sendPacket);

Read datagram
from server

clientSocket.receive(receivePacket);

DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);

String modifiedSentence =
new String(receivePacket.getData());
System.out.println("FROM SERVER:" + modifiedSentence);
clientSocket.close();
}
Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

31
Example: Java UDP server (1)

Create
datagram socket
at port 9876

public static void main(String args[])
{
DatagramSocket serverSocket = new DatagramSocket(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while(true)
{

Create space for
received datagram
Receive
datagram

DatagramPacket receivePacket =
new DatagramPacket(receiveData, receiveData.length);
serverSocket.receive(receivePacket);

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

32
Example: Java UDP server (2)
String sentence = new String(receivePacket.getData());

Get IP addr
port #, of
sender

InetAddress IPAddress = receivePacket.getAddress();
int port = receivePacket.getPort();
String capitalizedSentence = sentence.toUpperCase();
sendData = capitalizedSentence.getBytes();

Create datagram
to send to client

DatagramPacket sendPacket =
new DatagramPacket(sendData, sendData.length, IPAddress, port);

Write out
datagram
to socket

serverSocket.send(sendPacket);
}
}

End of while loop,
loop back and wait for
another datagram
Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

33
Electronic Mail
outgoing
message queue

Three major components:
• user agents
• mail servers
• Simple Mail Transfer Protocol
(SMTP)
User Agent
• a.k.a. “mail reader”
• composing, editing, reading mail
messages
• e.g., Eudora, Outlook, Elm,
Mozilla Thunderbird
• outgoing, incoming messages
stored on server

user
agent

user mailbox

mail
server

SMTP
SMTP
mail
server

SMTP

user
agent
mail
server

user
agent

user
agent

user
agent

user
agent

Java, Dr. Giuseppe Di Fatta, 2007-2013

34
Mail Servers
Mail Servers
• mailbox contains incoming
messages for user
• message queue of outgoing
(to be sent) mail messages
SMTP protocol between mail
servers to send email
messages
– client: sending mail server
– “server”: receiving mail
server

SMTP
mail
server

user
agent

SMTP
mail
server

SMTP
mail
server

Java, Dr. Giuseppe Di Fatta, 2007-2013

IMAP
or
POP3

user
agent
35
SMTP [RFC 2821]
http://tools.ietf.org/html/rfc2821
http://tools.ietf.org/html/rfc821

• uses TCP to reliably transfer email message from client to
server: TCP port 25
• direct transfer: sending server (or user client) to receiving server
• 3 phases of transfer
– handshaking (greeting)
– transfer of messages
– closure
• command/response interaction
– commands: ASCII text
– response: status code and phrase

• messages must be in 7-bit ASCII
Java, Dr. Giuseppe Di Fatta, 2007-2013

36
Try SMTP yourself
We can send email without
using an email client
(thunderbird, outlook, etc.)
We can talk SMTP directly to
the server:




telnet servername 25
see “220” reply from server
Commands:
–
–
–
–
–



HELO
MAIL FROM
RCPT TO
DATA
QUIT

Replies:
– 220 mailserver time
– 250 ok
– 500 unrecognized command
– 501 Syntactically invalid HELO
argument(s)

user
agent

SMTP

mail
server

telnet+SMTP
TCP
IP
Ethernet

telnet
connection
> telnet smtp.reading.ac.uk 25
220 vimp1.rdg.ac.uk ESMTP Exim Wed, 28 Feb 2007 16:40
helo whatsoever.blabla.org
250 vimp1.rdg.ac.uk Hello imogen.rdg.ac.uk
mail from: <myUserID@reading.ac.uk>
250 OK
rcpt to: <toSomeone@reading.ac.uk>
250 Accepted
data
354 Enter message, ending with "." on a line by itself
Hi there!
bye.
.
250 OK id=1HMRrh-0007OW-BX
quit
221 vimp1.rdg.ac.uk closing connection
>

– …
Java, Dr. Giuseppe Di Fatta, 2007-2013

37
SMTP: final words
• SMTP uses persistent connections
• SMTP requires message (header & body) to be in 7-bit ASCII
• SMTP server uses CRLF.CRLF to determine end of message
SMTP: protocol for exchanging
email msgs
RFC 822: standard for text
message format:
• header lines, e.g.,
– to, from, subject
different from SMTP commands!

• body

header

blank
line

body

– the message-body

• Termination sequence
– “n.n”
Java, Dr. Giuseppe Di Fatta, 2007-2013

38
Java Code: send an email (1/2)
private static void pause(int seconds) {
long msec = 1000 * seconds;
try {
Thread.sleep(msec);
} catch (InterruptedException e) {
}
}
public static String sendCommand(Socket theSocket, String cmd)
{
DataOutputStream outToServer = new DataOutputStream(theSocket.getOutputStream());
BufferedReader inFromServer = new BufferedReader(new
InputStreamReader(theSocket.getInputStream()));
pause(1); //needed for some MS servers!
System.out.println(“SENT TO SERVER: " + cmd);
outToServer.writeBytes(cmd + 'n');
String res = inFromServer.readLine();
System.out.println(“REPLY FROM SERVER: " + res);
System.out.println();
return res;
}

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

39
Java Code: send an email (2/2)
public static void main(String args[]) {
String mailServer = "smtp.reading.ac.uk";
int smtp_port = 25;
String myEmailAddress = "G.DiFatta@reading.ac.uk";
String dstAddress = "G.DiFatta@reading.ac.uk";
String command, answer;
Socket clientSocket = new Socket(mailServer, smtp_port);
command = "helo myself.uk";
answer = sendCommand(clientSocket, command);
command = "mail from: <" + myEmailAddress + ">";
answer = sendCommand(clientSocket, command);
command = "rcpt to: <" + dstAddress + ">";
answer = sendCommand(clientSocket, command);
command = "data";
answer = sendCommand(clientSocket, command);
//send the content of the email:
StringBuffer data = new StringBuffer();
data.append("blabla...n");
data.append("blabla...");
command = data.toString() + "n.n";
answer = sendCommand(clientSocket, command);
command = "quit";
answer = sendCommand(clientSocket, command);

clientSocket.close();
}

Note: to run this example you still need to add some code to manage exceptions.
Java, Dr. Giuseppe Di Fatta, 2007-2013

40
Java Example: a simple FTP client
String ftp_url="ftp://anonymous:na@ftp.fu-berlin.de/pub/misc/movies/database/";
String type = ";type=i";
String file1 = "filesizes";
try{
String filename=file1;
URL url = new URL(ftp_url+filename+type);
URLConnection urlc = url.openConnection();
InputStream is = urlc.getInputStream();
//For text files use BufferedReader and InputStreamReader
//For binary files use BufferedInputStream
BufferedReader bin = new BufferedReader(new InputStreamReader(is));
String line;
System.out.println("--------- "+filename+" -----------");
while((line = bin.readLine()) != null){
System.out.println(line);
}
System.out.println("--------------------");
bin.close();
} catch (MalformedURLException e1) {
System.out.println(e1);
e1.printStackTrace();
} catch (IOException e1) {
System.out.println(e1);
e1.printStackTrace();
}

Java, Dr. Giuseppe Di Fatta, 2007-2013

41
Conclusions
Java is:


Object-Oriented Programming (OOP) language



Strongly typed, data declarations, statements



A standard set of Application Programming Interfaces (API)

Main features:


Garbage collection



Threads



Exceptions



Network oriented 

 Network programming in Java is easy and fun.
These lecture slides are available at:
http://www.personal.reading.ac.uk/~sis06gd/resources.html
Java, Dr. Giuseppe Di Fatta, 2007-2013

42

Contenu connexe

Tendances

Tcp and introduction to protocol
Tcp and introduction to protocolTcp and introduction to protocol
Tcp and introduction to protocolSripati Mahapatra
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket TutorialGuo Albert
 
Socket programming or network programming
Socket programming or network programmingSocket programming or network programming
Socket programming or network programmingMmanan91
 
02 protocols and tcp-ip
02 protocols and tcp-ip02 protocols and tcp-ip
02 protocols and tcp-ipmyl_1116
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theoryMukesh Tekwani
 
Socket Programming
Socket ProgrammingSocket Programming
Socket ProgrammingCEC Landran
 
"Internet Protocol Suite" prepared by Szymon M. from Poland
"Internet Protocol Suite" prepared by Szymon M. from Poland"Internet Protocol Suite" prepared by Szymon M. from Poland
"Internet Protocol Suite" prepared by Szymon M. from Polandirenazd
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layerHasam Panezai
 
What is TCP/IP
What is TCP/IPWhat is TCP/IP
What is TCP/IPfarhan516
 
Lecture 5 internet-protocol_assignments
Lecture 5 internet-protocol_assignmentsLecture 5 internet-protocol_assignments
Lecture 5 internet-protocol_assignmentsSerious_SamSoul
 
Socket programming in C#
Socket programming in C#Socket programming in C#
Socket programming in C#Nang Luc Vu
 
FEGTS IP training - TCP/IP Introduction
FEGTS IP training - TCP/IP IntroductionFEGTS IP training - TCP/IP Introduction
FEGTS IP training - TCP/IP IntroductionKae Hsu
 

Tendances (20)

TCPIP
TCPIPTCPIP
TCPIP
 
Tcp and introduction to protocol
Tcp and introduction to protocolTcp and introduction to protocol
Tcp and introduction to protocol
 
Introduction to TCP/IP
Introduction to TCP/IPIntroduction to TCP/IP
Introduction to TCP/IP
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket Tutorial
 
Networking in java
Networking in javaNetworking in java
Networking in java
 
Socket programming or network programming
Socket programming or network programmingSocket programming or network programming
Socket programming or network programming
 
02 protocols and tcp-ip
02 protocols and tcp-ip02 protocols and tcp-ip
02 protocols and tcp-ip
 
Java networking programs - theory
Java networking programs - theoryJava networking programs - theory
Java networking programs - theory
 
Application layer protocols
Application layer protocolsApplication layer protocols
Application layer protocols
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Chap 1 Network Theory & Java Overview
Chap 1   Network Theory & Java OverviewChap 1   Network Theory & Java Overview
Chap 1 Network Theory & Java Overview
 
"Internet Protocol Suite" prepared by Szymon M. from Poland
"Internet Protocol Suite" prepared by Szymon M. from Poland"Internet Protocol Suite" prepared by Szymon M. from Poland
"Internet Protocol Suite" prepared by Szymon M. from Poland
 
Application Layer
Application LayerApplication Layer
Application Layer
 
Lecture application layer
Lecture application layerLecture application layer
Lecture application layer
 
What is TCP/IP
What is TCP/IPWhat is TCP/IP
What is TCP/IP
 
net work iTM3
net work iTM3net work iTM3
net work iTM3
 
TCP/IP Basics
TCP/IP BasicsTCP/IP Basics
TCP/IP Basics
 
Lecture 5 internet-protocol_assignments
Lecture 5 internet-protocol_assignmentsLecture 5 internet-protocol_assignments
Lecture 5 internet-protocol_assignments
 
Socket programming in C#
Socket programming in C#Socket programming in C#
Socket programming in C#
 
FEGTS IP training - TCP/IP Introduction
FEGTS IP training - TCP/IP IntroductionFEGTS IP training - TCP/IP Introduction
FEGTS IP training - TCP/IP Introduction
 

En vedette

Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets myrajendra
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming TutorialJignesh Patel
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
陳君翰 BB84 0718
陳君翰 BB84 0718陳君翰 BB84 0718
陳君翰 BB84 0718NTU PAS Lab
 
1.5 portable communication devices
1.5 portable communication devices1.5 portable communication devices
1.5 portable communication devicesHaa'Meem Mohiyuddin
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Kuldeep Jain
 
Point-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN pptPoint-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN pptNiaz Shaikh
 
Fundamental of Shell Programming
Fundamental of Shell ProgrammingFundamental of Shell Programming
Fundamental of Shell ProgrammingRahul Hada
 
Network Edge vs. Network Core: The Intelligence Battle
Network Edge vs. Network Core: The Intelligence BattleNetwork Edge vs. Network Core: The Intelligence Battle
Network Edge vs. Network Core: The Intelligence BattlePeter Jarich
 
Praktikum pemrograman jaringan-1-3
Praktikum pemrograman jaringan-1-3Praktikum pemrograman jaringan-1-3
Praktikum pemrograman jaringan-1-3sulaiman yunus
 
Tutorial BEX (Billing Explorer) 2007
Tutorial BEX (Billing Explorer) 2007Tutorial BEX (Billing Explorer) 2007
Tutorial BEX (Billing Explorer) 2007Dimaz Muda
 

En vedette (20)

Socket programming
Socket programmingSocket programming
Socket programming
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Socket Programming Tutorial
Socket Programming TutorialSocket Programming Tutorial
Socket Programming Tutorial
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
Tcp
TcpTcp
Tcp
 
陳君翰 BB84 0718
陳君翰 BB84 0718陳君翰 BB84 0718
陳君翰 BB84 0718
 
1.5 portable communication devices
1.5 portable communication devices1.5 portable communication devices
1.5 portable communication devices
 
Java networking
Java networkingJava networking
Java networking
 
Networking Basics
Networking BasicsNetworking Basics
Networking Basics
 
Jnp
JnpJnp
Jnp
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
Point-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN pptPoint-to-Point Protocol(PPP) CCN ppt
Point-to-Point Protocol(PPP) CCN ppt
 
Formation1 sockets
Formation1 socketsFormation1 sockets
Formation1 sockets
 
Tcp/ip model
Tcp/ip  modelTcp/ip  model
Tcp/ip model
 
Fundamental of Shell Programming
Fundamental of Shell ProgrammingFundamental of Shell Programming
Fundamental of Shell Programming
 
Network Edge vs. Network Core: The Intelligence Battle
Network Edge vs. Network Core: The Intelligence BattleNetwork Edge vs. Network Core: The Intelligence Battle
Network Edge vs. Network Core: The Intelligence Battle
 
Praktikum pemrograman jaringan-1-3
Praktikum pemrograman jaringan-1-3Praktikum pemrograman jaringan-1-3
Praktikum pemrograman jaringan-1-3
 
Tutorial BEX (Billing Explorer) 2007
Tutorial BEX (Billing Explorer) 2007Tutorial BEX (Billing Explorer) 2007
Tutorial BEX (Billing Explorer) 2007
 
Cara membagi bandwidth client komputer tanpa
Cara membagi bandwidth client komputer tanpaCara membagi bandwidth client komputer tanpa
Cara membagi bandwidth client komputer tanpa
 

Similaire à Network protocols and Java programming

Slides for protocol layering and network applications
Slides for protocol layering and network applicationsSlides for protocol layering and network applications
Slides for protocol layering and network applicationsjajinekkanti
 
Introduction to Computer Networking
Introduction to Computer NetworkingIntroduction to Computer Networking
Introduction to Computer Networkingshankars73
 
Datacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptDatacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptKristopher Hefner
 
Aplication and Transport layer- a practical approach
Aplication and Transport layer-  a practical approachAplication and Transport layer-  a practical approach
Aplication and Transport layer- a practical approachSarah R. Dowlath
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaIPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaVijiPriya Jeyamani
 
applicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptapplicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptDEEPAK948083
 
Computer network coe351- part2- final
Computer network coe351- part2- finalComputer network coe351- part2- final
Computer network coe351- part2- finalTaymoor Nazmy
 
Dc ch02 : protocol architecture
Dc ch02 : protocol architectureDc ch02 : protocol architecture
Dc ch02 : protocol architectureSyaiful Ahdan
 
Web technologies: recap on TCP-IP
Web technologies: recap on TCP-IPWeb technologies: recap on TCP-IP
Web technologies: recap on TCP-IPPiero Fraternali
 
protocol architecture
 protocol architecture protocol architecture
protocol architectureSrinivasa Rao
 
Lecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksLecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksAtif Shahzad
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manualJaya Prasanna
 
Introduction to OSI and QUIC
Introduction to OSI and QUICIntroduction to OSI and QUIC
Introduction to OSI and QUICFarzad Soltani
 

Similaire à Network protocols and Java programming (20)

Slides for protocol layering and network applications
Slides for protocol layering and network applicationsSlides for protocol layering and network applications
Slides for protocol layering and network applications
 
Introduction to Computer Networking
Introduction to Computer NetworkingIntroduction to Computer Networking
Introduction to Computer Networking
 
Datacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptDatacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.ppt
 
Aplication and Transport layer- a practical approach
Aplication and Transport layer-  a practical approachAplication and Transport layer-  a practical approach
Aplication and Transport layer- a practical approach
 
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriyaIPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
IPT Chapter 2 Web Services and Middleware - Dr. J. VijiPriya
 
applicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.pptapplicationapplicationapplicationapplication.ppt
applicationapplicationapplicationapplication.ppt
 
Introduction to socket programming nbv
Introduction to socket programming nbvIntroduction to socket programming nbv
Introduction to socket programming nbv
 
20CS2008 Computer Networks
20CS2008 Computer Networks 20CS2008 Computer Networks
20CS2008 Computer Networks
 
NP-lab-manual (1).pdf
NP-lab-manual (1).pdfNP-lab-manual (1).pdf
NP-lab-manual (1).pdf
 
NP-lab-manual.pdf
NP-lab-manual.pdfNP-lab-manual.pdf
NP-lab-manual.pdf
 
NP-lab-manual.docx
NP-lab-manual.docxNP-lab-manual.docx
NP-lab-manual.docx
 
Computer network coe351- part2- final
Computer network coe351- part2- finalComputer network coe351- part2- final
Computer network coe351- part2- final
 
Dc ch02 : protocol architecture
Dc ch02 : protocol architectureDc ch02 : protocol architecture
Dc ch02 : protocol architecture
 
Web technologies: recap on TCP-IP
Web technologies: recap on TCP-IPWeb technologies: recap on TCP-IP
Web technologies: recap on TCP-IP
 
Chapter2 Application
Chapter2 ApplicationChapter2 Application
Chapter2 Application
 
protocol architecture
 protocol architecture protocol architecture
protocol architecture
 
Lecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networksLecture12 ie321 dr_atifshahzad - networks
Lecture12 ie321 dr_atifshahzad - networks
 
Chapter2_L2.ppt
Chapter2_L2.pptChapter2_L2.ppt
Chapter2_L2.ppt
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manual
 
Introduction to OSI and QUIC
Introduction to OSI and QUICIntroduction to OSI and QUIC
Introduction to OSI and QUIC
 

Dernier

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 

Network protocols and Java programming

  • 1. School of Systems Engineering BSc Computer Science - “Java” (SE2JA11) Network Protocols in Java Dr. Giuseppe Di Fatta - Associate Professor of Computer Science Web: http://www.personal.reading.ac.uk/~sis06gd/ Email: G.DiFatta@reading.ac.uk - Director of the MSc Advanced Computer Science http://www.reading.ac.uk/sse/pg-taught/sse-mscadvancedcomputerscience.aspx These lecture slides are available at: http://www.personal.reading.ac.uk/~sis06gd/resources.html
  • 2. Outline  Introduction to Networking • Network protocols • Client-server network applications  Java Socket programming using TCP and UDP  Simple Mail Transfer Protocol (SMTP)  Code examples: • How to send an email in Java • How to implement a simple FTP client in Java Java, Dr. Giuseppe Di Fatta, 2007-2013 2
  • 3. What’s a protocol? human protocols: • “what’s the time?” • “I have a question” • introductions … specific msgs sent … specific actions taken when msgs received, or other events network protocols: • machines rather than humans • all communication activity in Internet governed by protocols A protocol defines: • format and order of messages sent and received among network entities • actions taken on message transmission, receipt Java, Dr. Giuseppe Di Fatta, 2007-2013 3
  • 4. What’s a protocol? a human protocol and a computer network protocol: Hi TCP connection req Hi TCP connection response Got the time? Get http://www.google.com/ 2:00 <file> time Java, Dr. Giuseppe Di Fatta, 2007-2013 4
  • 5. Internet protocol stack • application: supporting network applications – FTP, SMTP, STTP • transport: host-host data transfer – TCP, UDP • network: routing of datagrams from source to destination – IP, routing protocols • link: data transfer between neighboring network elements – PPP, Ethernet application transport network link physical • physical: bits “on the wire” Java, Dr. Giuseppe Di Fatta, 2007-2013 5
  • 6. Network applications: some jargon Process: program running user agent: interfaces with within a host. user “above” and network • within same host, two “below”. processes communicate • implements user interface using interprocess & application-level communication (defined by protocol OS). – Web: browser • processes running in – E-mail: mail reader different hosts – streaming audio/video: communicate with an media player application-layer protocol Java, Dr. Giuseppe Di Fatta, 2007-2013 6
  • 7. Applications and application-layer protocols Application: communicating, distributed processes – e.g., e-mail, Web, P2P file sharing, instant messaging – running in end systems (hosts) – exchange messages to implement application application transport network data link physical Application-layer protocols – one “piece” of an app – define messages exchanged by apps and actions taken – use communication services provided by lower layer protocols (TCP, UDP) application transport network data link physical Java, Dr. Giuseppe Di Fatta, 2007-2013 application transport network data link physical 7
  • 8. Application-Layer Protocol A protocol defines: • Types of messages exchanged, e.g., request & response messages • Syntax of message types: what fields in messages & how fields are delineated • Semantics of the fields, i.e., meaning of information in fields • Rules for when and how processes send & respond to messages Public-domain protocols: • standardised by IETF • allow for interoperability • e.g., HTTP, SMTP, FTP Example of P2P protocols: • BitTorrent Example of some proprietary P2P protocols: • KaZaA • Skype Java, Dr. Giuseppe Di Fatta, 2007-2013 8
  • 9. ARPANET-INTERNET Transition • The Internet was born on January 1st, 1983: when ARPANET changed from NCP to the TCP/IP protocol suite. – – Flag day: a change which requires a complete restart or conversion of a relevant software component or data. The change is large and expensive; reversing the change is difficult or impossible. “The goal is to make a complete switch over from the NCP to IP/TCP by 1 January 1983.” (Jon Postel, NCP/TCP Transition Plan, RFC 801) Bob Kahn and Vint Cerf - fathers of the Internet: inventors of the TCP/IP protocol suite Java, Dr. Giuseppe Di Fatta, 2007-2013 9
  • 10. IETF The Internet Engineering Task Force (IETF) is a loosely self-organized group of people who contribute to the engineering and evolution of Internet technologies. The IETF in no way "runs the Internet“. IETF quotes (believes)  Robert Kahn (interview, 2002): People don't think of the Internet as a logical architecture. They think of it as what AOL does. The Internet is an architectural philosophy, rather than a technology.  David Clark (1992-07-16, 24th IETF meeting): We reject: kings, presidents and voting. We believe in: rough consensus and running code.  Jon Postel (RFC 793 - September 1981) - Robustness Principle: TCP implementations will follow a general principle of robustness: be conservative in what you do, be liberal in what you accept from others. Jon Postel (1943-1998): see RFC 2468, October 1998 Java, Dr. Giuseppe Di Fatta, 2007-2013 10
  • 11. Client-Server Paradigm Typical network app has two pieces: client and server Client: • initiates contact with server (“speaks first”) • typically requests service from server, • Web: client implemented in browser; e-mail: in mail reader application transport network data link physical request Server: • provides requested service to client • e.g., Web server sends requested Web page, mail server delivers e-mail Java, Dr. Giuseppe Di Fatta, 2007-2013 reply application transport network data link physical 11
  • 12. Addressing Hosts and Processes • For a process to receive messages, it must have an identifier • Every host has a unique 32bit IP address • Q: does the IP address of the host on which the process runs suffice for identifying the process? • Answer: No, many processes can be running on same host • Identifier includes both the IP address and port numbers associated with the process on the host. • Example port numbers: – HTTP server: 80 – Mail server: 25 Java, Dr. Giuseppe Di Fatta, 2007-2013 12
  • 13. IP Addresses Current world population: 7 billion IP v4 addresses: 232 = 4 billion IP v6 addresses: 2128 Java, Dr. Giuseppe Di Fatta, 2007-2013 13
  • 14. Processes communicating across network • process sends/receives messages to/from its socket • socket analogous to door – sending process shoves message out door – sending process assumes transport infrastructure on other side of door which brings message to socket at receiving process host or server host or server process controlled by app developer process socket socket TCP with buffers, variables Internet TCP with buffers, variables controlled by OS • API: (1) choice of transport protocol; (2) ability to fix a few parameters Java, Dr. Giuseppe Di Fatta, 2007-2013 14
  • 15. Internet transport protocols services TCP service: UDP service: • connection-oriented: setup required between client and server processes • reliable transport between sending and receiving process • flow control: sender won’t overwhelm receiver • congestion control: throttle sender when network overloaded • does not providing: timing, minimum bandwidth guarantees • unreliable data transfer between sending and receiving process • does not provide: connection setup, reliability, flow control, congestion control, timing, or bandwidth guarantee Q: why bother? Why is there a UDP? Java, Dr. Giuseppe Di Fatta, 2007-2013 15
  • 16. Internet Applications Application e-mail remote terminal access Web file transfer streaming multimedia Internet telephony Application layer protocol Underlying transport protocol SMTP [RFC 2821] Telnet [RFC 854] HTTP [RFC 2616] FTP [RFC 959] proprietary TCP TCP TCP TCP TCP or UDP proprietary typically UDP Java, Dr. Giuseppe Di Fatta, 2007-2013 16
  • 17. Socket programming Goal: learn how to build client/server application that communicate using sockets. Socket API • introduced in BSD4.1 UNIX, 1981 • explicitly created, used, released by applications • client/server paradigm • two types of transport service via socket API: – unreliable datagram (UDP) – reliable, byte stream-oriented (TCP) socket a host-local, application-created, OS-controlled interface (a “door”) into which application process can both send and receive messages to/from another application process. Java, Dr. Giuseppe Di Fatta, 2007-2013 17
  • 18. Socket-programming using TCP Socket: a door between application process and end-end-transport protocol (UCP or TCP) TCP service: reliable transfer of bytes from one process to another controlled by application developer controlled by operating system process process socket TCP with buffers, variables host or server internet socket TCP with buffers, variables controlled by application developer controlled by operating system host or server Java, Dr. Giuseppe Di Fatta, 2007-2013 18
  • 19. Socket programming with TCP Client must contact server • server process must first be running • server must have created socket (door) that welcomes client’s contact Client contacts server by: • creating client-local TCP socket • specifying IP address, port number of server process • When client creates socket: client TCP establishes connection to server TCP • When contacted by client, server TCP creates new socket for server process to communicate with client – allows server to talk with multiple clients – source port numbers used to distinguish clients application viewpoint TCP provides reliable, in-order transfer of bytes (“pipe”) between client and server Java, Dr. Giuseppe Di Fatta, 2007-2013 19
  • 20. Stream jargon stream of bytes file stream of bytes stream of bytes Process • A stream is a sequence of characters that flow into or out of a process. • An input stream is attached to some input source for the process, eg, keyboard or socket. • An output stream is attached to an output source, eg, monitor or socket. Input streams Internet Output streams stream of bytes file stream of bytes stream of bytes Java, Dr. Giuseppe Di Fatta, 2007-2013 Internet 20
  • 21. Socket programming with TCP Process Client Process output stream monitor inFromUser input stream outToServer 1) client reads line from standard input (inFromUser stream) , sends to server via socket (outToServer stream) 2) server reads line from socket 3) server converts line to uppercase, sends back to client 4) client reads, prints modified line from socket (inFromServer stream) keyboard inFromServer Example client-server app: input stream client TCP clientSocket socket to network Java, Dr. Giuseppe Di Fatta, 2007-2013 TCP socket from network 21
  • 22. Client/server socket interaction: TCP 2 4 Server Client TCP connection 3 -1 1 create socket for incoming request: welcomeSocket = ServerSocket() TCP connection setup wait for incoming connection request connectionSocket = welcomeSocket.accept() read request from connectionSocket write reply to connectionSocket close connectionSocket 2 3 create socket to server 0 clientSocket = Socket() reliable fullduplex channel 1 send request using clientSocket read reply from 4 clientSocket close clientSocket Java, Dr. Giuseppe Di Fatta, 2007-2013 22
  • 23. Example: Java TCP client (1) public static void main(String argv[]) { String sentence; String modifiedSentence; Create input stream Create client socket, connect to server Create output stream attached to socket BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); Socket clientSocket = new Socket("hostname", 6789); DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 23
  • 24. Example: Java TCP client (2) Create input stream attached to socket BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = inFromUser.readLine(); Send line to server outToServer.writeBytes(sentence + 'n'); Read line from server modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); clientSocket.close(); } Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 24
  • 25. Example: Java TCP server (1) Create welcoming socket at port 6789 Wait, on welcoming socket for contact by client Create input stream, attached to socket public static void main(String argv[]) { String clientSentence; String capitalizedSentence; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) { Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream())); Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 25
  • 26. Example: Java TCP server (2) Create output stream, attached to socket DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream()); Read in line from socket clientSentence = inFromClient.readLine(); capitalizedSentence = clientSentence.toUpperCase() + 'n'; Write out line to socket outToClient.writeBytes(capitalizedSentence); } } End of while loop, loop back and wait for another client connection Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 26
  • 27. Socket programming with UDP UDP: no “connection” between client and server • no handshaking • sender explicitly attaches IP address and port of destination to each packet • server must extract IP address, port of sender from received packet application viewpoint UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server UDP: transmitted data may be received out of order, or lost Java, Dr. Giuseppe Di Fatta, 2007-2013 27
  • 28. Client/server socket interaction: UDP Server (running on hostid) create socket, port=x, for incoming request: serverSocket = DatagramSocket() read request from serverSocket write reply to serverSocket specifying client host address, port number Client create socket, clientSocket = DatagramSocket() Create, address (hostid, port=x, send datagram request using clientSocket read reply from clientSocket close clientSocket Java, Dr. Giuseppe Di Fatta, 2007-2013 28
  • 29. Example: Java client (UDP) input stream Client process monitor inFromUser keyboard Process Input: receives packet (TCP received “byte stream”) UDP packet receivePacket packet (TCP sent “byte stream”) sendPacket Output: sends client UDP clientSocket socket to network UDP packet UDP socket from network Java, Dr. Giuseppe Di Fatta, 2007-2013 29
  • 30. Example: Java UDP client (1) Create input stream Create client socket Translate hostname to IP address using DNS public static void main(String args[]) { BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); DatagramSocket clientSocket = new DatagramSocket(); InetAddress IPAddress = InetAddress.getByName("hostname"); byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024]; String sentence = inFromUser.readLine(); sendData = sentence.getBytes(); Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 30
  • 31. Example: Java UDP client (2) Create datagram with data-to-send, length, IP addr, port DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9876); Send datagram to server clientSocket.send(sendPacket); Read datagram from server clientSocket.receive(receivePacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); String modifiedSentence = new String(receivePacket.getData()); System.out.println("FROM SERVER:" + modifiedSentence); clientSocket.close(); } Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 31
  • 32. Example: Java UDP server (1) Create datagram socket at port 9876 public static void main(String args[]) { DatagramSocket serverSocket = new DatagramSocket(9876); byte[] receiveData = new byte[1024]; byte[] sendData = new byte[1024]; while(true) { Create space for received datagram Receive datagram DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); serverSocket.receive(receivePacket); Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 32
  • 33. Example: Java UDP server (2) String sentence = new String(receivePacket.getData()); Get IP addr port #, of sender InetAddress IPAddress = receivePacket.getAddress(); int port = receivePacket.getPort(); String capitalizedSentence = sentence.toUpperCase(); sendData = capitalizedSentence.getBytes(); Create datagram to send to client DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, port); Write out datagram to socket serverSocket.send(sendPacket); } } End of while loop, loop back and wait for another datagram Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 33
  • 34. Electronic Mail outgoing message queue Three major components: • user agents • mail servers • Simple Mail Transfer Protocol (SMTP) User Agent • a.k.a. “mail reader” • composing, editing, reading mail messages • e.g., Eudora, Outlook, Elm, Mozilla Thunderbird • outgoing, incoming messages stored on server user agent user mailbox mail server SMTP SMTP mail server SMTP user agent mail server user agent user agent user agent user agent Java, Dr. Giuseppe Di Fatta, 2007-2013 34
  • 35. Mail Servers Mail Servers • mailbox contains incoming messages for user • message queue of outgoing (to be sent) mail messages SMTP protocol between mail servers to send email messages – client: sending mail server – “server”: receiving mail server SMTP mail server user agent SMTP mail server SMTP mail server Java, Dr. Giuseppe Di Fatta, 2007-2013 IMAP or POP3 user agent 35
  • 36. SMTP [RFC 2821] http://tools.ietf.org/html/rfc2821 http://tools.ietf.org/html/rfc821 • uses TCP to reliably transfer email message from client to server: TCP port 25 • direct transfer: sending server (or user client) to receiving server • 3 phases of transfer – handshaking (greeting) – transfer of messages – closure • command/response interaction – commands: ASCII text – response: status code and phrase • messages must be in 7-bit ASCII Java, Dr. Giuseppe Di Fatta, 2007-2013 36
  • 37. Try SMTP yourself We can send email without using an email client (thunderbird, outlook, etc.) We can talk SMTP directly to the server:    telnet servername 25 see “220” reply from server Commands: – – – – –  HELO MAIL FROM RCPT TO DATA QUIT Replies: – 220 mailserver time – 250 ok – 500 unrecognized command – 501 Syntactically invalid HELO argument(s) user agent SMTP mail server telnet+SMTP TCP IP Ethernet telnet connection > telnet smtp.reading.ac.uk 25 220 vimp1.rdg.ac.uk ESMTP Exim Wed, 28 Feb 2007 16:40 helo whatsoever.blabla.org 250 vimp1.rdg.ac.uk Hello imogen.rdg.ac.uk mail from: <myUserID@reading.ac.uk> 250 OK rcpt to: <toSomeone@reading.ac.uk> 250 Accepted data 354 Enter message, ending with "." on a line by itself Hi there! bye. . 250 OK id=1HMRrh-0007OW-BX quit 221 vimp1.rdg.ac.uk closing connection > – … Java, Dr. Giuseppe Di Fatta, 2007-2013 37
  • 38. SMTP: final words • SMTP uses persistent connections • SMTP requires message (header & body) to be in 7-bit ASCII • SMTP server uses CRLF.CRLF to determine end of message SMTP: protocol for exchanging email msgs RFC 822: standard for text message format: • header lines, e.g., – to, from, subject different from SMTP commands! • body header blank line body – the message-body • Termination sequence – “n.n” Java, Dr. Giuseppe Di Fatta, 2007-2013 38
  • 39. Java Code: send an email (1/2) private static void pause(int seconds) { long msec = 1000 * seconds; try { Thread.sleep(msec); } catch (InterruptedException e) { } } public static String sendCommand(Socket theSocket, String cmd) { DataOutputStream outToServer = new DataOutputStream(theSocket.getOutputStream()); BufferedReader inFromServer = new BufferedReader(new InputStreamReader(theSocket.getInputStream())); pause(1); //needed for some MS servers! System.out.println(“SENT TO SERVER: " + cmd); outToServer.writeBytes(cmd + 'n'); String res = inFromServer.readLine(); System.out.println(“REPLY FROM SERVER: " + res); System.out.println(); return res; } Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 39
  • 40. Java Code: send an email (2/2) public static void main(String args[]) { String mailServer = "smtp.reading.ac.uk"; int smtp_port = 25; String myEmailAddress = "G.DiFatta@reading.ac.uk"; String dstAddress = "G.DiFatta@reading.ac.uk"; String command, answer; Socket clientSocket = new Socket(mailServer, smtp_port); command = "helo myself.uk"; answer = sendCommand(clientSocket, command); command = "mail from: <" + myEmailAddress + ">"; answer = sendCommand(clientSocket, command); command = "rcpt to: <" + dstAddress + ">"; answer = sendCommand(clientSocket, command); command = "data"; answer = sendCommand(clientSocket, command); //send the content of the email: StringBuffer data = new StringBuffer(); data.append("blabla...n"); data.append("blabla..."); command = data.toString() + "n.n"; answer = sendCommand(clientSocket, command); command = "quit"; answer = sendCommand(clientSocket, command); clientSocket.close(); } Note: to run this example you still need to add some code to manage exceptions. Java, Dr. Giuseppe Di Fatta, 2007-2013 40
  • 41. Java Example: a simple FTP client String ftp_url="ftp://anonymous:na@ftp.fu-berlin.de/pub/misc/movies/database/"; String type = ";type=i"; String file1 = "filesizes"; try{ String filename=file1; URL url = new URL(ftp_url+filename+type); URLConnection urlc = url.openConnection(); InputStream is = urlc.getInputStream(); //For text files use BufferedReader and InputStreamReader //For binary files use BufferedInputStream BufferedReader bin = new BufferedReader(new InputStreamReader(is)); String line; System.out.println("--------- "+filename+" -----------"); while((line = bin.readLine()) != null){ System.out.println(line); } System.out.println("--------------------"); bin.close(); } catch (MalformedURLException e1) { System.out.println(e1); e1.printStackTrace(); } catch (IOException e1) { System.out.println(e1); e1.printStackTrace(); } Java, Dr. Giuseppe Di Fatta, 2007-2013 41
  • 42. Conclusions Java is:  Object-Oriented Programming (OOP) language  Strongly typed, data declarations, statements  A standard set of Application Programming Interfaces (API) Main features:  Garbage collection  Threads  Exceptions  Network oriented   Network programming in Java is easy and fun. These lecture slides are available at: http://www.personal.reading.ac.uk/~sis06gd/resources.html Java, Dr. Giuseppe Di Fatta, 2007-2013 42