SlideShare a Scribd company logo
1 of 27
•Protocol,
•Sockets,
•Knowing IP Address,
•URL,
•Reading the Source Code of a Web Page,
•Downloading a Web Page from Internet,
•Downloading an Image from Internet,
•A TCP/IP Server,
•A TCP/IP Client,
•A UDP Server, A UDP Client,
•File Server,
•File Client,
•Two-Way Communication between Server and Client,
•Sending a Simple Mail,
Interconnection of computer is called a
network.
A simple network can be formed by
connecting two computers using a cable.
So network can have two computers or
two thousand computers.
For ex. Internet
Advantage of network is sharing the
resources.
For ex. Bank customer
A Computer networking model where one
or more powerful computers (servers)
provide the different computer network
services and all other user'of
computer network (clients) access those
services to perform user's tasks is known
as client/server computer networking
model.
 In such networks, there exists a central
controller called server.
 A server is a specialized computer that controls
the network resources and provides services to
other computers in the network.
 All other computers in the network are called
clients.
 A client computer receives the requested
services from a server.
 A server performs all the major operations like
security and network management.
 All the clients communicate with each other via
centralized server
pros of Client Server Networks
• Centralized back up is possible.
• Use of dedicated server improves the performance
of whole system.
cons of Client Server Networks
• It requires specialized servers with large memory
and secondary storage. This leads to increase in the
cost.
• The cost of network operating system that manages
the various clients is also high.
• It requires dedicated network administrator.
Hardware: includes computers, cables,
modems, routers, hubs, etc.
Software: Includes programs to
communicate b/w servers and clients.
Protocol: Represents a way to establish
connection and helps in sending and
receiving data in a standard format.
 A protocol represents a set of rules to be followed by
every computer on the network.
 Protocol is useful to physically move data from one
place to another place on a network.
 While sending data or receiving data, the computer
wants to send a file on a network, it is not possible to
send the entire file in a single step.
 The file should be broken into small pieces and then
only they can be sent to other computer.
 Two types protocol which other protocols are
developed.
• TCP/IP Protocol
• UDP
TCP (Transmission Control Protocol) /IP
(internet protocol) is the standard protocol
model used on any network, including
internet.
TCP/IP model has five layers.
• Application layer
• TCP
• IP
• Data Link Layer
• Physical Layer
 UDP is another protocol that transfer data in a
connection less and unreliable manner.
 It will not check how many bits are sent or how many
bits are actually received at the other side.
 During transmission of data, there may be loss of
some bits.
 Also, the data sent may not be received in the same
order.
 So, UDP is not used to send text.
 UDP is used to send images, audio files, and
video files.
 Even if some bits are lost, still the image or audio file
can be composed with a slight variation that will not
disturb the original image or audio.
 Establish a connecting point b/w a server and a client
so the communication done through that point called
socket.
 Socket programming is a way of connecting two
nodes on a network to communicate with each other.
 One socket(node) listens on a particular port at an IP,
while other socket reaches out to the other to form a
connection.
 Server forms the listener socket while client reaches
out to the server.
 They are the real backbones behind web browsing. In
simpler terms there is a server and a client.
 Every new service on the net should be assigned a
new port number.
Each socket given an identification
number, which is called port number.
Port number takes 2 bytes and can be
from 0 to 65,535.
Port Number Application or service
13 Date and time services
21 FTP which transfer files
23 telnet, which provides remote login
25 SMTP, which delivers mails
67 BOOTP, which provides configuration at boot time
80 HTTP, which transfer web pages
109 POP2, which is a mailing service
110 POP3, which is a mailing service
119 NNTP, which is for transferring news articles
443 HTTPS, which transfer web pages securely
 To create a socket, you must use
the socket.socket() function available in socket module,
which has the general syntax −
• s = socket.socket (socket_family, socket_type, protocol=0)
 Here, first argument ‘socket family’ indicates which
version of the ip address should be used, whether IP
address version 4 or version 6.
 This argument can take either of the following two values:
• socket.AF_INET #IPV4 – this is default
• socket.AF_INET6 #IPV6
 The second argument is ‘type’ which represents the type
of the protocol to be used, whether TCP/IP or UDP.
 Following two values:
• socket.SOCK_STREAM #for TCP –this is default
• socket.SOCK_DGRAM #for UDP
To know the IP address of a website on
internet, we can use gethostbyname()
function available in socket module.
This function takes the website name and
returns its ip address.
• Addr=socket.gethostbyname(‘www.google.co.in’)
 If there is no such website on internet, then it
return ‘gaierror’ (Get Address Information Error)
URL (Uniform resource locator) represents
the address that is specified to access some
information or resource on internet. For ex.
http://www.google.com:80/index.html
• The protocol to use http://
• The server name or ip address of the server
(www.google.com)
• 3rd part port number, which is optional (:80)
• Last part is the file that is referred.
When url is given we can parse the url and
find out all the parts of the url with the help
of urlparse() function of urllib.parse module
in python.
It returns a tuple containing the parts of the
url.
Tpl= urllib.aprse.urlparse(‘urlstring’)
Following attributes are used to retrieve
the individual parts of the url.
Scheme: this gives the protocol name
used in the url
Netloc: gives the website name on the net
with port number if present.
Path: gives the path of the web page.
Port: gives the port number
A server is a program that provides services
to other computers on the network or internet.
Similarly a client is a program that receives
services from the server.
When a server wants to communicate with a
client, there is a need of a socket.
A socket is a point of connection b/w the
server and client.
1. Create a TCP/IP socket at server side using
socket() function.
2. Bind the socket with host name and port
number using bind((host,port)) method.
3. Specify maximum number of connection
using listen(1) method.
4. Server should wait till a client accepts
connection.
 C, addr= s.accept() # c is a connection obj, addr
adddress of client
5. send(b”msgstring”) method to send
message to client. Message should be sent in
the form of byte streams.
6. Convert message in binary format use
string.encode() method.
7. Close the connection using close() method.
A client is a program that receives the data
or services from the server.
Steps for client program
1. Create socket obj using socket() function.
2. Use connect((host,port)) method to connect
the socket.
3. Receive msg from the server use
recv(1024) method. Here, 1024 is buffer
size that is bytes received from the server.
4. Disconnect the client using close() method.
If we want to create a server that uses UDP
protocol to send messages. We have to
specify socket.SOCK_DGRAM in socket obj.
Using sendto() function the server can send
data to client, but UDP is a connection-less
protocol, server does not know where the
data shoud be sent, so we specify the client
address in sendto() method.
• S.sendto(“msg string”,(host,port))
1. At the client side socket should be
created using socket function.
2. Socket should be bind using
bind((host,port)) method.
3. The client can receive messages with the
help of recvfrom(1024) method.
4. Receive all messages using while loop.
5. And settimeout(5) method so client will
automatically disconnect after that time
elapses.
File Server & File Client
Two way communication b/w
server and client
Sending a simple Email

More Related Content

What's hot

Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)UC San Diego
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageDr.YNM
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and DjangoMichael Pirnat
 
Java Serialization
Java SerializationJava Serialization
Java Serializationimypraz
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Pedro Rodrigues
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming LanguageLaxman Puri
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)PyData
 

What's hot (20)

Java Networking
Java NetworkingJava Networking
Java Networking
 
Socket programming in Java (PPTX)
Socket programming in Java (PPTX)Socket programming in Java (PPTX)
Socket programming in Java (PPTX)
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Networking in Java
Networking in JavaNetworking in Java
Networking in Java
 
Java arrays
Java arraysJava arrays
Java arrays
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Web Development with Python and Django
Web Development with Python and DjangoWeb Development with Python and Django
Web Development with Python and Django
 
Java Serialization
Java SerializationJava Serialization
Java Serialization
 
Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)Introduction to the basics of Python programming (part 1)
Introduction to the basics of Python programming (part 1)
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
Python my sql database connection
Python my sql   database connectionPython my sql   database connection
Python my sql database connection
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Network security
Network securityNetwork security
Network security
 
Basic socket programming
Basic socket programmingBasic socket programming
Basic socket programming
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)Introduction to NumPy (PyData SV 2013)
Introduction to NumPy (PyData SV 2013)
 
Python Basics.pdf
Python Basics.pdfPython Basics.pdf
Python Basics.pdf
 

Similar to Networking in python by Rj

PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAMaulik Borsaniya
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxRockyBhai46825
 
Socket Programming
Socket ProgrammingSocket Programming
Socket ProgrammingCEC Landran
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manualJaya Prasanna
 
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptxEsubesisay
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programmingelliando dias
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
presentation on TCP/IP protocols data comunications
presentation on TCP/IP protocols data comunicationspresentation on TCP/IP protocols data comunications
presentation on TCP/IP protocols data comunicationsAnyapuPranav
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxssuser23035c
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project ReportKavita Sharma
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 

Similar to Networking in python by Rj (20)

Md13 networking
Md13 networkingMd13 networking
Md13 networking
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Lecture set 7
Lecture set 7Lecture set 7
Lecture set 7
 
Final networks lab manual
Final networks lab manualFinal networks lab manual
Final networks lab manual
 
Intake 38 11
Intake 38 11Intake 38 11
Intake 38 11
 
Networking.pptx
Networking.pptxNetworking.pptx
Networking.pptx
 
Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
presentation on TCP/IP protocols data comunications
presentation on TCP/IP protocols data comunicationspresentation on TCP/IP protocols data comunications
presentation on TCP/IP protocols data comunications
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
28 networking
28  networking28  networking
28 networking
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
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
 

More from Shree M.L.Kakadiya MCA mahila college, Amreli

More from Shree M.L.Kakadiya MCA mahila college, Amreli (20)

Machine Learning by Rj
Machine Learning by RjMachine Learning by Rj
Machine Learning by Rj
 
Listeners and filters in servlet
Listeners and filters in servletListeners and filters in servlet
Listeners and filters in servlet
 
Servlet unit 2
Servlet unit 2 Servlet unit 2
Servlet unit 2
 
Servlet by Rj
Servlet by RjServlet by Rj
Servlet by Rj
 
Research paper on python by Rj
Research paper on python by RjResearch paper on python by Rj
Research paper on python by Rj
 
Jsp in Servlet by Rj
Jsp in Servlet by RjJsp in Servlet by Rj
Jsp in Servlet by Rj
 
Motion capture by Rj
Motion capture by RjMotion capture by Rj
Motion capture by Rj
 
Research paper on big data and hadoop
Research paper on big data and hadoopResearch paper on big data and hadoop
Research paper on big data and hadoop
 
Text processing by Rj
Text processing by RjText processing by Rj
Text processing by Rj
 
Python and data analytics
Python and data analyticsPython and data analytics
Python and data analytics
 
Multithreading by rj
Multithreading by rjMultithreading by rj
Multithreading by rj
 
Django by rj
Django by rjDjango by rj
Django by rj
 
Database programming
Database programmingDatabase programming
Database programming
 
CGI by rj
CGI by rjCGI by rj
CGI by rj
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Seminar on Project Management by Rj
Seminar on Project Management by RjSeminar on Project Management by Rj
Seminar on Project Management by Rj
 
Spring by rj
Spring by rjSpring by rj
Spring by rj
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Leadership & Motivation
Leadership & MotivationLeadership & Motivation
Leadership & Motivation
 
Event handling
Event handlingEvent handling
Event handling
 

Recently uploaded

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
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
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 

Recently uploaded (20)

Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
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
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
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)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
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!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 

Networking in python by Rj

  • 1. •Protocol, •Sockets, •Knowing IP Address, •URL, •Reading the Source Code of a Web Page, •Downloading a Web Page from Internet, •Downloading an Image from Internet, •A TCP/IP Server, •A TCP/IP Client, •A UDP Server, A UDP Client, •File Server, •File Client, •Two-Way Communication between Server and Client, •Sending a Simple Mail,
  • 2. Interconnection of computer is called a network. A simple network can be formed by connecting two computers using a cable. So network can have two computers or two thousand computers. For ex. Internet Advantage of network is sharing the resources. For ex. Bank customer
  • 3. A Computer networking model where one or more powerful computers (servers) provide the different computer network services and all other user'of computer network (clients) access those services to perform user's tasks is known as client/server computer networking model.
  • 4.  In such networks, there exists a central controller called server.  A server is a specialized computer that controls the network resources and provides services to other computers in the network.  All other computers in the network are called clients.  A client computer receives the requested services from a server.  A server performs all the major operations like security and network management.  All the clients communicate with each other via centralized server
  • 5.
  • 6. pros of Client Server Networks • Centralized back up is possible. • Use of dedicated server improves the performance of whole system. cons of Client Server Networks • It requires specialized servers with large memory and secondary storage. This leads to increase in the cost. • The cost of network operating system that manages the various clients is also high. • It requires dedicated network administrator.
  • 7. Hardware: includes computers, cables, modems, routers, hubs, etc. Software: Includes programs to communicate b/w servers and clients. Protocol: Represents a way to establish connection and helps in sending and receiving data in a standard format.
  • 8.  A protocol represents a set of rules to be followed by every computer on the network.  Protocol is useful to physically move data from one place to another place on a network.  While sending data or receiving data, the computer wants to send a file on a network, it is not possible to send the entire file in a single step.  The file should be broken into small pieces and then only they can be sent to other computer.  Two types protocol which other protocols are developed. • TCP/IP Protocol • UDP
  • 9. TCP (Transmission Control Protocol) /IP (internet protocol) is the standard protocol model used on any network, including internet. TCP/IP model has five layers. • Application layer • TCP • IP • Data Link Layer • Physical Layer
  • 10.  UDP is another protocol that transfer data in a connection less and unreliable manner.  It will not check how many bits are sent or how many bits are actually received at the other side.  During transmission of data, there may be loss of some bits.  Also, the data sent may not be received in the same order.  So, UDP is not used to send text.  UDP is used to send images, audio files, and video files.  Even if some bits are lost, still the image or audio file can be composed with a slight variation that will not disturb the original image or audio.
  • 11.  Establish a connecting point b/w a server and a client so the communication done through that point called socket.  Socket programming is a way of connecting two nodes on a network to communicate with each other.  One socket(node) listens on a particular port at an IP, while other socket reaches out to the other to form a connection.  Server forms the listener socket while client reaches out to the server.  They are the real backbones behind web browsing. In simpler terms there is a server and a client.  Every new service on the net should be assigned a new port number.
  • 12. Each socket given an identification number, which is called port number. Port number takes 2 bytes and can be from 0 to 65,535.
  • 13. Port Number Application or service 13 Date and time services 21 FTP which transfer files 23 telnet, which provides remote login 25 SMTP, which delivers mails 67 BOOTP, which provides configuration at boot time 80 HTTP, which transfer web pages 109 POP2, which is a mailing service 110 POP3, which is a mailing service 119 NNTP, which is for transferring news articles 443 HTTPS, which transfer web pages securely
  • 14.  To create a socket, you must use the socket.socket() function available in socket module, which has the general syntax − • s = socket.socket (socket_family, socket_type, protocol=0)  Here, first argument ‘socket family’ indicates which version of the ip address should be used, whether IP address version 4 or version 6.  This argument can take either of the following two values: • socket.AF_INET #IPV4 – this is default • socket.AF_INET6 #IPV6  The second argument is ‘type’ which represents the type of the protocol to be used, whether TCP/IP or UDP.  Following two values: • socket.SOCK_STREAM #for TCP –this is default • socket.SOCK_DGRAM #for UDP
  • 15. To know the IP address of a website on internet, we can use gethostbyname() function available in socket module. This function takes the website name and returns its ip address. • Addr=socket.gethostbyname(‘www.google.co.in’)  If there is no such website on internet, then it return ‘gaierror’ (Get Address Information Error)
  • 16. URL (Uniform resource locator) represents the address that is specified to access some information or resource on internet. For ex. http://www.google.com:80/index.html • The protocol to use http:// • The server name or ip address of the server (www.google.com) • 3rd part port number, which is optional (:80) • Last part is the file that is referred.
  • 17. When url is given we can parse the url and find out all the parts of the url with the help of urlparse() function of urllib.parse module in python. It returns a tuple containing the parts of the url. Tpl= urllib.aprse.urlparse(‘urlstring’) Following attributes are used to retrieve the individual parts of the url.
  • 18. Scheme: this gives the protocol name used in the url Netloc: gives the website name on the net with port number if present. Path: gives the path of the web page. Port: gives the port number
  • 19. A server is a program that provides services to other computers on the network or internet. Similarly a client is a program that receives services from the server. When a server wants to communicate with a client, there is a need of a socket. A socket is a point of connection b/w the server and client.
  • 20. 1. Create a TCP/IP socket at server side using socket() function. 2. Bind the socket with host name and port number using bind((host,port)) method. 3. Specify maximum number of connection using listen(1) method. 4. Server should wait till a client accepts connection.  C, addr= s.accept() # c is a connection obj, addr adddress of client
  • 21. 5. send(b”msgstring”) method to send message to client. Message should be sent in the form of byte streams. 6. Convert message in binary format use string.encode() method. 7. Close the connection using close() method.
  • 22. A client is a program that receives the data or services from the server. Steps for client program 1. Create socket obj using socket() function. 2. Use connect((host,port)) method to connect the socket. 3. Receive msg from the server use recv(1024) method. Here, 1024 is buffer size that is bytes received from the server. 4. Disconnect the client using close() method.
  • 23. If we want to create a server that uses UDP protocol to send messages. We have to specify socket.SOCK_DGRAM in socket obj. Using sendto() function the server can send data to client, but UDP is a connection-less protocol, server does not know where the data shoud be sent, so we specify the client address in sendto() method. • S.sendto(“msg string”,(host,port))
  • 24. 1. At the client side socket should be created using socket function. 2. Socket should be bind using bind((host,port)) method. 3. The client can receive messages with the help of recvfrom(1024) method. 4. Receive all messages using while loop. 5. And settimeout(5) method so client will automatically disconnect after that time elapses.
  • 25. File Server & File Client
  • 26. Two way communication b/w server and client