SlideShare a Scribd company logo
Distributed Systems
Lecture -1-
Created by :
Eng. Ghadeer Al Hasan
TCP vs. UDP
Connection-oriented vs. Connectionless 1
TCP UDP
TCP is a connection-orientedprotocol.
Connection-orientationmeans that the
communicating devices should establisha
connectionbefore transmitting data and
should close the connectionafter
transmitting the data.
UDP is the Datagramorientedprotocol.
This is because there is no overhead for
opening a connection, maintaining a
connection, And terminating a connection.
UDP is efficientFor broadcast and multicast
type of networktransmission.
Reliability 2
TCP UDP
TCP provides the delivery guarantee,
whichmeans a message sent using TCP
protocol is guaranteedto be delivered to
the client. If a message is lost in transits
thenits recovered using resending, which
is handled by TCP protocol itself
UDP is unreliable, it doesn't provide any
deliveryguarantee. A datagrampackage
may be lost in transits. That's why UDP is
not suitable for programs which require
guaranteed delivery.
Error Checking 3
TCP UDP
TCP provides extensive error checking
mechanisms. It is becauseit provides flow
control and acknowledgment of data.
UDP has only the basic error checking
mechanismusing checksums.
Ordering 4
TCP UDP
TCP guarantees the order of message. The
message will be delivered to the client in
the same order, the server has sent, though
it's possible they may reach out of order to
the other end of the network. TCP protocol
will do all sequencing and ordering for
you
UDP doesn't provide any ordering or
sequencing guarantee.
Speed 5
TCP UDP
TCP is slow.
TCP does has to createa connection,
ensure guaranteedand ordereddelivery, it
does a lot more than UDP.
UPDis fast.
UDP is more suitable where speed is a
concern, for example, online video
streaming, telecast or online multiplayer
games
Retransmission 6
TCP UDP
Retransmissionof lost packets is possible
in TCP.
There is no retransmission of lost packets in
User DatagramProtocol (UDP).
Heavyweight vs. Lightweight 7
TCP UDP
TCP is heavyweight.
Because of the overheadmentionedabove
UPDis lightweight.
UDP is deliver a message without bearing
any overhead of creating connection and
guaranteeing deliveryor order guarantee
keeps it light weight.
Header Size 8
TCP UDP
TCP has bigger header thanUDP.
TCP header size is 20 bytes.
UPDhas smallest header than TCP.
UDP Header size is 8 bytes.
Congestion or Flow Control 9
TCP UDP
TCP does Flow Control. It requires three
packets to set up a socket connection
before any userdata can be sent.
TCP handles reliabilityand congestion
control.
UDP does not havean option for flow
control.
Using 10
TCP UDP
TCP is usedby HTTP, HTTPs, FTP, SMTP
and Telnet
UDP is used by DNS, DHCP, TFTP, SNMP,
RIP, and VoIP.
Socket Programming in Java
Server Side Programming… 12
Establisha Socket Connection
- To write a server application two sockets are needed.
- A ServerSocket which waits for the client requests (when a client makes a new Socket())
- Socket socket to use for communication withthe client.
ServerSocket serverSocket = new ServerSocket(PORT);
1st argument: TCPport
Server Side Programming 13
Communication
- getOutputStream() method is usedto send the output through the socket.
- getInputStream() method is used to receive the input through the socket.
Close the Connection
- After finishing, it is important to close theconnectionby closing thesocket as well as input/output
streams.
Client Side Programming 14
Establisha Socket Connection :
- To connect to other machine we needa socket connection.
- A socket connectionmeans the two machines have informationabout eachother’s networklocation
- (IP Address) and TCP port
- The java.net.Socket classrepresents a Socket
Socket socket = new Socket(“127.0.0.1”, 5000)
- 1st argument : IP address of Server (127.0.0.1 is the IP address of local host)
- 2nd argument : TCP Port (Just a number representing which application to run on a
server, e.g. : HTTP runs on port 80, Port number can be from0 to 65535)
Client Side Programming… 15
- Communication :
To communicateover a socket connection, streams are used to bothinputand output the data.
- Closing the connection:
The socket connection is closed explicitly oncethe message to server is sent
Java Implementation
16
private Socket socket = null;
private ServerSocket serverSocket = null;
private DataInputStream input = null;
Server Side
private void openSocket(){
try{
serverSocket = new ServerSocket(Constants.PORT);
log("Server Started...");
}catch(IOException ex){
log("start server : " + ex.getMessage());
}
}
private void waitingConnection(){
log("Waiting for client...");
try {
socket = serverSocket.accept();
log("Client accepted");
} catch (IOException ex) {
log("waiting Connection : " + ex.getMessage());
}
}
set it zero, what
is happens?
17
private void openInputStream(){
try{
input = new DataInputStream(
new BufferedInputStream(socket.getInputStream()));
}catch(IOException ex){
log("open InputStream : " + ex.getMessage());
}
}
Server Side…
private String read(){
String line = "";
try{
line = input.readUTF();
}catch(IOException ex){
log("read : " + ex.getMessage());
}
return line;
}
private void closeInputStream(){
try{
input.close();
}catch(IOException ex){
log("close Input Stream : " + ex.getMessage());
}
}
18
private void closeSocket(){
try{
serverSocket.close();
socket.close();
}catch(IOException ex){
log("close socket : " + ex.getMessage());
}
}
Server Side…
private void log(String message){
System.out.println(message);
}
19
private void startConnection(){
openSocket();
waitingConnection();
openInputStream();
}
Server Side…
private void Connecting(){
String line = "";
while(! line.equals(Constants.STOP)){
line = read();
System.out.println("Client : " + line);
}
}
private void stopConnection(){
closeSocket();
closeInputStream();
}
20Server Side…
public static void main(String[] args){
Server server = new Server();
server.startConnection();
server.Connecting();
server.stopConnection();
}
21
private Socket socket = null;
private DataInputStream input = null;
private DataOutputStream output = null;
Client Side
private void openSocket(){
try{
socket= new Socket(Constants.IP, Constants.PORT);
}catch(UnknownHostException ex){
log("openSocket : " + ex.getMessage());
}catch(IOException ex){
log("openSocket : " + ex.getMessage());
}
} private void openStreams(){
try{
input = new DataInputStream((System.in));
output = new DataOutputStream(socket.getOutputStream());
}catch(IOException ex){
log("openStreams : " + ex.getMessage());
}
}
22
private void closeStreams(){
try{
input.close();
output.close();
}catch(IOException ex){
log("closeStreams : " + ex.getMessage());
}
}
Client Side…
private void closeSocket(){
try{
socket.close();
}catch(IOException ex){
log("closeSocket : " + ex.getMessage());
}
} private String read(){
String line = "";
try{
line = input.readLine();
}catch(IOException ex){
log("read : " + ex.getMessage());
}
return line;
}
23
private void write(String message){
try{
output.writeUTF(message);
}catch(IOException ex){
log("write : " + ex.getMessage());
}
}
Client Side…
private String read(){
String line = "";
try{
line = input.readLine();
}catch(IOException ex){
log("read : " + ex.getMessage());
}
return line;
}
24
private void startConnection(){
openSocket();
if(socket != null){
openStreams();
}
log("Start Client");
}
Client Side…
private void connecting(){
String line = "";
while(! line.equals(Constants.STOP)){
line = read();
write(line);
}
}
private void stopConnection(){
closeStreams();
closeSocket();
log("Close Client");
}
25Client Side…
public static void main(String[] args) {
Client client = new Client();
client.startConnection();
client.connecting();
client.stopConnection();
}
26Run
References 28
- YouTube link
https://www.youtube.com/playlist?list=PLtDIUAtyP4lhV7CsYfLuIx26UeG4J-ujZ
- GitHub
https://github.com/Ghadeerof
End Lecture

More Related Content

What's hot

TCP vs UDP / Sumiet23
TCP vs UDP / Sumiet23TCP vs UDP / Sumiet23
TCP vs UDP / Sumiet23
Sumiet Talekar
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Socketselliando dias
 
Chap 19 ftp & tftp
Chap 19 ftp & tftpChap 19 ftp & tftp
Chap 19 ftp & tftp
Noctorous Jamal
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using JavaRahul Hada
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface
CEC Landran
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
myrajendra
 
Udp
UdpUdp
Tcp vs udp difference and comparison diffen
Tcp vs udp   difference and comparison   diffenTcp vs udp   difference and comparison   diffen
Tcp vs udp difference and comparison diffen
Harikiran Raju
 
Tcpip
TcpipTcpip
Tcp vs udp
Tcp vs udpTcp vs udp
Tcp vs udp
hassamkhaliq
 
What is the difference between udp and tcp internet protocols
What is the difference between udp and tcp internet protocols What is the difference between udp and tcp internet protocols
What is the difference between udp and tcp internet protocols krupalipandya29
 

What's hot (20)

IPC SOCKET
IPC SOCKETIPC SOCKET
IPC SOCKET
 
TCP vs UDP / Sumiet23
TCP vs UDP / Sumiet23TCP vs UDP / Sumiet23
TCP vs UDP / Sumiet23
 
Programming TCP/IP with Sockets
Programming TCP/IP with SocketsProgramming TCP/IP with Sockets
Programming TCP/IP with Sockets
 
Np unit2
Np unit2Np unit2
Np unit2
 
Lect16
Lect16Lect16
Lect16
 
Chap 19 ftp & tftp
Chap 19 ftp & tftpChap 19 ftp & tftp
Chap 19 ftp & tftp
 
Np unit iv ii
Np unit iv iiNp unit iv ii
Np unit iv ii
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using Java
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
 
Puertos tcp & udp
Puertos tcp & udpPuertos tcp & udp
Puertos tcp & udp
 
Udp
UdpUdp
Udp
 
Tcp vs udp difference and comparison diffen
Tcp vs udp   difference and comparison   diffenTcp vs udp   difference and comparison   diffen
Tcp vs udp difference and comparison diffen
 
Ch21
Ch21Ch21
Ch21
 
Udp vs-tcp
Udp vs-tcpUdp vs-tcp
Udp vs-tcp
 
Tcpip
TcpipTcpip
Tcpip
 
Tcpdump
TcpdumpTcpdump
Tcpdump
 
Tcp vs udp
Tcp vs udpTcp vs udp
Tcp vs udp
 
What is the difference between udp and tcp internet protocols
What is the difference between udp and tcp internet protocols What is the difference between udp and tcp internet protocols
What is the difference between udp and tcp internet protocols
 
Udp Programming
Udp ProgrammingUdp Programming
Udp Programming
 

Similar to #1 (TCPvs. UDP)

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
Tushar B Kute
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
Maulik Borsaniya
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
Techvilla
 
Socket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdfSocket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdf
PraveenKumar187040
 
07 coms 525 tcpip - udp
07    coms 525 tcpip - udp07    coms 525 tcpip - udp
07 coms 525 tcpip - udp
Palanivel Kuppusamy
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
Maryna Vasina
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
Cleveroad
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
Peter R. Egli
 
Sockets
Sockets Sockets
Sockets
babu4b4u
 

Similar to #1 (TCPvs. UDP) (20)

Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Sockets
SocketsSockets
Sockets
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
 
Networking
NetworkingNetworking
Networking
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
 
Socket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdfSocket Programming TCP:IP PPT.pdf
Socket Programming TCP:IP PPT.pdf
 
Python networking
Python networkingPython networking
Python networking
 
28 networking
28  networking28  networking
28 networking
 
Ipc
IpcIpc
Ipc
 
07 coms 525 tcpip - udp
07    coms 525 tcpip - udp07    coms 525 tcpip - udp
07 coms 525 tcpip - udp
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
 
Socket.io v.0.8.3
Socket.io v.0.8.3Socket.io v.0.8.3
Socket.io v.0.8.3
 
Network Sockets
Network SocketsNetwork Sockets
Network Sockets
 
Sockets
Sockets Sockets
Sockets
 

More from Ghadeer AlHasan

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes
Ghadeer AlHasan
 
[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files
Ghadeer AlHasan
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List
Ghadeer AlHasan
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner Class
Ghadeer AlHasan
 
[C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers [C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers
Ghadeer AlHasan
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
Ghadeer AlHasan
 
[C++] #5 - Structures
[C++] #5 - Structures[C++] #5 - Structures
[C++] #5 - Structures
Ghadeer AlHasan
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections Framework
Ghadeer AlHasan
 
5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java
Ghadeer AlHasan
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading
Ghadeer AlHasan
 
3- Operators in Java
3- Operators in Java3- Operators in Java
3- Operators in Java
Ghadeer AlHasan
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
Ghadeer AlHasan
 
1- Introduction to java
1- Introduction to java1- Introduction to java
1- Introduction to java
Ghadeer AlHasan
 
0- Overview
0- Overview0- Overview
0- Overview
Ghadeer AlHasan
 
4- Arrays
4-  Arrays4-  Arrays
4- Arrays
Ghadeer AlHasan
 
3- Functions
3-  Functions3-  Functions
3- Functions
Ghadeer AlHasan
 
2- Control Structures
2-  Control Structures2-  Control Structures
2- Control Structures
Ghadeer AlHasan
 
1- Languages Basics
1- Languages Basics1- Languages Basics
1- Languages Basics
Ghadeer AlHasan
 
#8 (Java Message Service)
#8 (Java Message Service)#8 (Java Message Service)
#8 (Java Message Service)
Ghadeer AlHasan
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
Ghadeer AlHasan
 

More from Ghadeer AlHasan (20)

[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes[C++ Tutorial ] #9 Classes
[C++ Tutorial ] #9 Classes
 
[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files[C++ Tutorial] #8 Files
[C++ Tutorial] #8 Files
 
[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List[C++ Tutorial] #7- Linked List
[C++ Tutorial] #7- Linked List
 
[Java] #8 String and Inner Class
[Java] #8 String and Inner Class[Java] #8 String and Inner Class
[Java] #8 String and Inner Class
 
[C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers [C++ Tutorial] #6- Pointers
[C++ Tutorial] #6- Pointers
 
[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream[Java] #7 - Input & Output Stream
[Java] #7 - Input & Output Stream
 
[C++] #5 - Structures
[C++] #5 - Structures[C++] #5 - Structures
[C++] #5 - Structures
 
#6- Arrays and Collections Framework
#6- Arrays and Collections Framework#6- Arrays and Collections Framework
#6- Arrays and Collections Framework
 
5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java5- Overriding and Abstraction In Java
5- Overriding and Abstraction In Java
 
4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading4- Inheritance, Aggregation, Encapsulation and Overloading
4- Inheritance, Aggregation, Encapsulation and Overloading
 
3- Operators in Java
3- Operators in Java3- Operators in Java
3- Operators in Java
 
2- Introduction to java II
2-  Introduction to java II2-  Introduction to java II
2- Introduction to java II
 
1- Introduction to java
1- Introduction to java1- Introduction to java
1- Introduction to java
 
0- Overview
0- Overview0- Overview
0- Overview
 
4- Arrays
4-  Arrays4-  Arrays
4- Arrays
 
3- Functions
3-  Functions3-  Functions
3- Functions
 
2- Control Structures
2-  Control Structures2-  Control Structures
2- Control Structures
 
1- Languages Basics
1- Languages Basics1- Languages Basics
1- Languages Basics
 
#8 (Java Message Service)
#8 (Java Message Service)#8 (Java Message Service)
#8 (Java Message Service)
 
#7 (Java Message Service)
#7 (Java Message Service)#7 (Java Message Service)
#7 (Java Message Service)
 

Recently uploaded

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
SupreethSP4
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
obonagu
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
manasideore6
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
Robbie Edward Sayers
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
R&R Consult
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 

Recently uploaded (20)

一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Runway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptxRunway Orientation Based on the Wind Rose Diagram.pptx
Runway Orientation Based on the Wind Rose Diagram.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
在线办理(ANU毕业证书)澳洲国立大学毕业证录取通知书一模一样
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Fundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptxFundamentals of Electric Drives and its applications.pptx
Fundamentals of Electric Drives and its applications.pptx
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
HYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generationHYDROPOWER - Hydroelectric power generation
HYDROPOWER - Hydroelectric power generation
 
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxCFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptx
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 

#1 (TCPvs. UDP)

  • 1. Distributed Systems Lecture -1- Created by : Eng. Ghadeer Al Hasan TCP vs. UDP
  • 2. Connection-oriented vs. Connectionless 1 TCP UDP TCP is a connection-orientedprotocol. Connection-orientationmeans that the communicating devices should establisha connectionbefore transmitting data and should close the connectionafter transmitting the data. UDP is the Datagramorientedprotocol. This is because there is no overhead for opening a connection, maintaining a connection, And terminating a connection. UDP is efficientFor broadcast and multicast type of networktransmission.
  • 3. Reliability 2 TCP UDP TCP provides the delivery guarantee, whichmeans a message sent using TCP protocol is guaranteedto be delivered to the client. If a message is lost in transits thenits recovered using resending, which is handled by TCP protocol itself UDP is unreliable, it doesn't provide any deliveryguarantee. A datagrampackage may be lost in transits. That's why UDP is not suitable for programs which require guaranteed delivery.
  • 4. Error Checking 3 TCP UDP TCP provides extensive error checking mechanisms. It is becauseit provides flow control and acknowledgment of data. UDP has only the basic error checking mechanismusing checksums.
  • 5. Ordering 4 TCP UDP TCP guarantees the order of message. The message will be delivered to the client in the same order, the server has sent, though it's possible they may reach out of order to the other end of the network. TCP protocol will do all sequencing and ordering for you UDP doesn't provide any ordering or sequencing guarantee.
  • 6. Speed 5 TCP UDP TCP is slow. TCP does has to createa connection, ensure guaranteedand ordereddelivery, it does a lot more than UDP. UPDis fast. UDP is more suitable where speed is a concern, for example, online video streaming, telecast or online multiplayer games
  • 7. Retransmission 6 TCP UDP Retransmissionof lost packets is possible in TCP. There is no retransmission of lost packets in User DatagramProtocol (UDP).
  • 8. Heavyweight vs. Lightweight 7 TCP UDP TCP is heavyweight. Because of the overheadmentionedabove UPDis lightweight. UDP is deliver a message without bearing any overhead of creating connection and guaranteeing deliveryor order guarantee keeps it light weight.
  • 9. Header Size 8 TCP UDP TCP has bigger header thanUDP. TCP header size is 20 bytes. UPDhas smallest header than TCP. UDP Header size is 8 bytes.
  • 10. Congestion or Flow Control 9 TCP UDP TCP does Flow Control. It requires three packets to set up a socket connection before any userdata can be sent. TCP handles reliabilityand congestion control. UDP does not havean option for flow control.
  • 11. Using 10 TCP UDP TCP is usedby HTTP, HTTPs, FTP, SMTP and Telnet UDP is used by DNS, DHCP, TFTP, SNMP, RIP, and VoIP.
  • 13. Server Side Programming… 12 Establisha Socket Connection - To write a server application two sockets are needed. - A ServerSocket which waits for the client requests (when a client makes a new Socket()) - Socket socket to use for communication withthe client. ServerSocket serverSocket = new ServerSocket(PORT); 1st argument: TCPport
  • 14. Server Side Programming 13 Communication - getOutputStream() method is usedto send the output through the socket. - getInputStream() method is used to receive the input through the socket. Close the Connection - After finishing, it is important to close theconnectionby closing thesocket as well as input/output streams.
  • 15. Client Side Programming 14 Establisha Socket Connection : - To connect to other machine we needa socket connection. - A socket connectionmeans the two machines have informationabout eachother’s networklocation - (IP Address) and TCP port - The java.net.Socket classrepresents a Socket Socket socket = new Socket(“127.0.0.1”, 5000) - 1st argument : IP address of Server (127.0.0.1 is the IP address of local host) - 2nd argument : TCP Port (Just a number representing which application to run on a server, e.g. : HTTP runs on port 80, Port number can be from0 to 65535)
  • 16. Client Side Programming… 15 - Communication : To communicateover a socket connection, streams are used to bothinputand output the data. - Closing the connection: The socket connection is closed explicitly oncethe message to server is sent
  • 18. 16 private Socket socket = null; private ServerSocket serverSocket = null; private DataInputStream input = null; Server Side private void openSocket(){ try{ serverSocket = new ServerSocket(Constants.PORT); log("Server Started..."); }catch(IOException ex){ log("start server : " + ex.getMessage()); } } private void waitingConnection(){ log("Waiting for client..."); try { socket = serverSocket.accept(); log("Client accepted"); } catch (IOException ex) { log("waiting Connection : " + ex.getMessage()); } } set it zero, what is happens?
  • 19. 17 private void openInputStream(){ try{ input = new DataInputStream( new BufferedInputStream(socket.getInputStream())); }catch(IOException ex){ log("open InputStream : " + ex.getMessage()); } } Server Side… private String read(){ String line = ""; try{ line = input.readUTF(); }catch(IOException ex){ log("read : " + ex.getMessage()); } return line; } private void closeInputStream(){ try{ input.close(); }catch(IOException ex){ log("close Input Stream : " + ex.getMessage()); } }
  • 20. 18 private void closeSocket(){ try{ serverSocket.close(); socket.close(); }catch(IOException ex){ log("close socket : " + ex.getMessage()); } } Server Side… private void log(String message){ System.out.println(message); }
  • 21. 19 private void startConnection(){ openSocket(); waitingConnection(); openInputStream(); } Server Side… private void Connecting(){ String line = ""; while(! line.equals(Constants.STOP)){ line = read(); System.out.println("Client : " + line); } } private void stopConnection(){ closeSocket(); closeInputStream(); }
  • 22. 20Server Side… public static void main(String[] args){ Server server = new Server(); server.startConnection(); server.Connecting(); server.stopConnection(); }
  • 23. 21 private Socket socket = null; private DataInputStream input = null; private DataOutputStream output = null; Client Side private void openSocket(){ try{ socket= new Socket(Constants.IP, Constants.PORT); }catch(UnknownHostException ex){ log("openSocket : " + ex.getMessage()); }catch(IOException ex){ log("openSocket : " + ex.getMessage()); } } private void openStreams(){ try{ input = new DataInputStream((System.in)); output = new DataOutputStream(socket.getOutputStream()); }catch(IOException ex){ log("openStreams : " + ex.getMessage()); } }
  • 24. 22 private void closeStreams(){ try{ input.close(); output.close(); }catch(IOException ex){ log("closeStreams : " + ex.getMessage()); } } Client Side… private void closeSocket(){ try{ socket.close(); }catch(IOException ex){ log("closeSocket : " + ex.getMessage()); } } private String read(){ String line = ""; try{ line = input.readLine(); }catch(IOException ex){ log("read : " + ex.getMessage()); } return line; }
  • 25. 23 private void write(String message){ try{ output.writeUTF(message); }catch(IOException ex){ log("write : " + ex.getMessage()); } } Client Side… private String read(){ String line = ""; try{ line = input.readLine(); }catch(IOException ex){ log("read : " + ex.getMessage()); } return line; }
  • 26. 24 private void startConnection(){ openSocket(); if(socket != null){ openStreams(); } log("Start Client"); } Client Side… private void connecting(){ String line = ""; while(! line.equals(Constants.STOP)){ line = read(); write(line); } } private void stopConnection(){ closeStreams(); closeSocket(); log("Close Client"); }
  • 27. 25Client Side… public static void main(String[] args) { Client client = new Client(); client.startConnection(); client.connecting(); client.stopConnection(); }
  • 28. 26Run
  • 29. References 28 - YouTube link https://www.youtube.com/playlist?list=PLtDIUAtyP4lhV7CsYfLuIx26UeG4J-ujZ - GitHub https://github.com/Ghadeerof