SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
SOCKET PROGRAMMING IN JAVA



             Narendran Thangarajan,
             @naren_live,
             II Year, BE, CSE,
             SSN College of Engg, Chennai.
What started it all..
 Internet has emerged as a global ubiquitous
  media for communication

 It has changed the way we live, learn, enjoy,
  communicate, interact, engage, etc.

 To take advantage of this, businesses are
  ceaselessly trying to offer their services through
  the internet.

 So a huge demand for software developers good
  in creating internet-enabled applications.
Client Server Applications

        The Web Service is provided by the server
        and the clients use these services


   Client
                                             Server
                        Network


Client machine
                                       Server machine
        A client, where sockets and network
            This is
                    A server, come in !!
Sockets
 Introduced in BSD 4.1 UNIX 1981.


 Sockets are the endpoints of any
  communication over the internet.

 Sockets are identified by socket addresses.


 Socket Address = IP Address + Port Number
Why IP Address + Port number?
 • IP Address is of the form 10.0.0.1

 • Port Number can be anything from 0 to 65,535.
Destination Socket = 10.0.0.2 : 80

IP Address – Choose network

                      20.0.0.0



     10.0.0.0                     30.0.0.0




                       40.0.0.0
Destination Socket = 10.0.0.2 : 80


IP Address -> MAC Address – Locate the
                          specific system



            10.0.0.1

        10.0.0.2
Port Number – Process specific
Port 10000



                           Port 11000




                         Port 120000
Understanding Ports

         OutLook             AVG
Gmail               YM
         Express            Update




Port 1    Port 2   Port 3   Port 4

          Transport Layer
                                         Packet

                                         Port num    data


                                     Network layer
 Thus virtually, sockets are a connection
  between the two processes in different
  systems.

 Eg : Let the socket pairs be
   10.0.0.1 : 80 and 20.0.0.1 : 2000
   192.168.21.10 : 3000 and 192.168.100.1 : 6000
Networking Basics – the larger picture

     Applications Layer
       Standard apps
         HTTP             TCP STACK
         FTP
         Telnet               Application
       User apps          (http,ftp,telnet,…)
     Transport Layer           Transport
       TCP                   (TCP, UDP,..)
       UDP
                                Network
     Network Layer              (IP,..)
       IP
     Link Layer                  Link
                            (device driver,..)
       Device drivers
Network Basics - Where are these sockets?

      Applications Layer
          Standard apps
            HTTP              TCP STACK
            FTP
            Telnet                Application
          User apps           (http,ftp,telnet,…)


     Programming Interface:      Sockets
          SOCKETS

                                    Transport
      Transport Layer            (TCP, UDP,..)
          TCP
          UDP                      Network
                                     (IP,..)
        Network Layer                Link
            IP
        Link Layer
                                (device driver,..)
            Device drivers
Now into Socket
 programming..
Socket Programming with TCP
 Server starts first..
   Server Process must be running first
   Server must have created a socket which welcomes
     client’s connection. (Welcoming socket)
 Client contacts server by..
   Creating Client local TCP socket
   Specify IP Address and port number of server process.
   When Client socket is created, the connection is
    established.
   When connection is established, server creates a new
    socket (Connection Socket) to communicate with that
    client and the Welcoming socket is once again waiting
    for connections for other clients.
Client/Server Socket Interaction in
TCP
       Server
     create socket,
     port=x, for
     incoming request:
     welcomeSocket =
         ServerSocket()                          Client
     wait for incoming
                          TCP                create socket,
     connection request   connection setup   connect to hostid, port=x
     connectionSocket =                      clientSocket =
     welcomeSocket.accept()                         Socket()

                                               send request using
     read request from                         clientSocket
     connectionSocket

     write reply to
     connectionSocket                          read reply from
                                               connectionSocket
     close
     connectionSocket                           close
                                                clientSocket
Step 1 :
                        Connection request
            port
   Server
                                                    Client




Step 2 :
             port




   Server




                                             port
                                                    Client
    port            Connection
Types of Sockets in TCP

 ServerSocket – the socket used by servers
 Socket – Socket used by clients


 Create a ServerSocket in the server and make
  it to wait for connections from Sockets from
  other clients
The concept of Streams
       Client output    Server input
       stream           stream



     Client              Server
     socket              socket




    Client input       Server output
    stream             stream
Socket Programming with UDP

 No Connection between client and server.
   No handshaking
   The sender has to explicitly mention the IP
    address and the port of the destination.
   The server should extract the IP Address of the
    datagram everytime.


 Uses DatagramSocket.
Client/server socket interaction:
UDP
   Server                   Client
  create socket,       create socket,
  port=x, for          clientSocket =
  incoming request:    DatagramSocket()
  serverSocket =
  DatagramSocket()
                       Create, address (hostid, port=x),
                       send datagram request
                       using clientSocket
   read request from
   serverSocket

   write reply to
   serverSocket
                        read reply from
   specifying client
                        clientSocket
   host address,
   port number           close
                         clientSocket
Coding time..
Conclusion

 Socket Programming is very easy in Java.


 Usually each and every socket is handled by a
  separate thread in real-time client/server
  environments.
Queries

Weitere ähnliche Inhalte

Was ist angesagt?

Socket programming
Socket programmingSocket programming
Socket programmingNemiRathore
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Luzan Baral
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And MultithreadingShraddha
 
Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Java multi threading
Java multi threadingJava multi threading
Java multi threadingRaja Sekhar
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
Java Networking
Java NetworkingJava Networking
Java NetworkingSunil OS
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAvasuraj pandey
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Ippon
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jspJafar Nesargi
 

Was ist angesagt? (20)

Servlets
ServletsServlets
Servlets
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)Java DataBase Connectivity API (JDBC API)
Java DataBase Connectivity API (JDBC API)
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Tcp/ip server sockets
Tcp/ip server socketsTcp/ip server sockets
Tcp/ip server sockets
 
Java multi threading
Java multi threadingJava multi threading
Java multi threading
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Web api
Web apiWeb api
Web api
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
Servlets
ServletsServlets
Servlets
 
Java Networking
Java NetworkingJava Networking
Java Networking
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Basic of Multithreading in JAva
Basic of Multithreading in JAvaBasic of Multithreading in JAva
Basic of Multithreading in JAva
 
Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014Formation Spring Avancé gratuite par Ippon 2014
Formation Spring Avancé gratuite par Ippon 2014
 
Spring MVC Framework
Spring MVC FrameworkSpring MVC Framework
Spring MVC Framework
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Jdbc_ravi_2016
Jdbc_ravi_2016Jdbc_ravi_2016
Jdbc_ravi_2016
 

Ähnlich wie Socket programming using java

Ähnlich wie Socket programming using java (20)

Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Client server project
Client server projectClient server project
Client server project
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
 
Sockets
SocketsSockets
Sockets
 
Client server chat application
Client server chat applicationClient server chat application
Client server chat application
 
Java Network Programming.pptx
Java Network Programming.pptxJava Network Programming.pptx
Java Network Programming.pptx
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
 
Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
 
Socket Programming_theory.ppt
Socket Programming_theory.pptSocket Programming_theory.ppt
Socket Programming_theory.ppt
 
Java 1
Java 1Java 1
Java 1
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
 
Socket & Server Socket
Socket & Server SocketSocket & Server Socket
Socket & Server Socket
 
17-Networking.pdf
17-Networking.pdf17-Networking.pdf
17-Networking.pdf
 
EN-04 (1).pptx
EN-04 (1).pptxEN-04 (1).pptx
EN-04 (1).pptx
 
Understanding computer networks
Understanding computer networksUnderstanding computer networks
Understanding computer networks
 
Raspberry pi Part 23
Raspberry pi Part 23Raspberry pi Part 23
Raspberry pi Part 23
 
Os 2
Os 2Os 2
Os 2
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
 

Mehr von UC San Diego

A primer on network devices
A primer on network devicesA primer on network devices
A primer on network devicesUC San Diego
 
Datacenter traffic demand characterization
Datacenter traffic demand characterizationDatacenter traffic demand characterization
Datacenter traffic demand characterizationUC San Diego
 
Smart Homes, Buildings and Internet-of-things
Smart Homes, Buildings and Internet-of-thingsSmart Homes, Buildings and Internet-of-things
Smart Homes, Buildings and Internet-of-thingsUC San Diego
 
Social Networks analysis to characterize HIV at-risk populations - Progress a...
Social Networks analysis to characterize HIV at-risk populations - Progress a...Social Networks analysis to characterize HIV at-risk populations - Progress a...
Social Networks analysis to characterize HIV at-risk populations - Progress a...UC San Diego
 
eyeTalk - A system for helping people affected by motor neuron problems
eyeTalk - A system for helping people affected by motor neuron problemseyeTalk - A system for helping people affected by motor neuron problems
eyeTalk - A system for helping people affected by motor neuron problemsUC San Diego
 
Basic terminologies for a developer
Basic terminologies for a developerBasic terminologies for a developer
Basic terminologies for a developerUC San Diego
 
Fields in computer science
Fields in computer scienceFields in computer science
Fields in computer scienceUC San Diego
 
Network Programming with Umit project
Network Programming with Umit projectNetwork Programming with Umit project
Network Programming with Umit projectUC San Diego
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonUC San Diego
 
Airline reservation system db design
Airline reservation system db designAirline reservation system db design
Airline reservation system db designUC San Diego
 
Workshop on Network Security
Workshop on Network SecurityWorkshop on Network Security
Workshop on Network SecurityUC San Diego
 
Android application development
Android application developmentAndroid application development
Android application developmentUC San Diego
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application ArchitectureUC San Diego
 

Mehr von UC San Diego (18)

A primer on network devices
A primer on network devicesA primer on network devices
A primer on network devices
 
Datacenter traffic demand characterization
Datacenter traffic demand characterizationDatacenter traffic demand characterization
Datacenter traffic demand characterization
 
Smart Homes, Buildings and Internet-of-things
Smart Homes, Buildings and Internet-of-thingsSmart Homes, Buildings and Internet-of-things
Smart Homes, Buildings and Internet-of-things
 
Social Networks analysis to characterize HIV at-risk populations - Progress a...
Social Networks analysis to characterize HIV at-risk populations - Progress a...Social Networks analysis to characterize HIV at-risk populations - Progress a...
Social Networks analysis to characterize HIV at-risk populations - Progress a...
 
eyeTalk - A system for helping people affected by motor neuron problems
eyeTalk - A system for helping people affected by motor neuron problemseyeTalk - A system for helping people affected by motor neuron problems
eyeTalk - A system for helping people affected by motor neuron problems
 
Pirc net poster
Pirc net posterPirc net poster
Pirc net poster
 
Ajaxism
AjaxismAjaxism
Ajaxism
 
Basic terminologies for a developer
Basic terminologies for a developerBasic terminologies for a developer
Basic terminologies for a developer
 
Fields in computer science
Fields in computer scienceFields in computer science
Fields in computer science
 
FOSS Introduction
FOSS IntroductionFOSS Introduction
FOSS Introduction
 
Network Programming with Umit project
Network Programming with Umit projectNetwork Programming with Umit project
Network Programming with Umit project
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Airline reservation system db design
Airline reservation system db designAirline reservation system db design
Airline reservation system db design
 
Workshop on Network Security
Workshop on Network SecurityWorkshop on Network Security
Workshop on Network Security
 
Routing basics
Routing basicsRouting basics
Routing basics
 
Technology Quiz
Technology QuizTechnology Quiz
Technology Quiz
 
Android application development
Android application developmentAndroid application development
Android application development
 
Pervasive Web Application Architecture
Pervasive Web Application ArchitecturePervasive Web Application Architecture
Pervasive Web Application Architecture
 

Kürzlich hochgeladen

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxleah joy valeriano
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 

Kürzlich hochgeladen (20)

ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptxMusic 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
Music 9 - 4th quarter - Vocal Music of the Romantic Period.pptx
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 

Socket programming using java

  • 1. SOCKET PROGRAMMING IN JAVA Narendran Thangarajan, @naren_live, II Year, BE, CSE, SSN College of Engg, Chennai.
  • 2. What started it all..  Internet has emerged as a global ubiquitous media for communication  It has changed the way we live, learn, enjoy, communicate, interact, engage, etc.  To take advantage of this, businesses are ceaselessly trying to offer their services through the internet.  So a huge demand for software developers good in creating internet-enabled applications.
  • 3. Client Server Applications The Web Service is provided by the server and the clients use these services Client Server Network Client machine Server machine A client, where sockets and network This is A server, come in !!
  • 4. Sockets  Introduced in BSD 4.1 UNIX 1981.  Sockets are the endpoints of any communication over the internet.  Sockets are identified by socket addresses.  Socket Address = IP Address + Port Number
  • 5. Why IP Address + Port number? • IP Address is of the form 10.0.0.1 • Port Number can be anything from 0 to 65,535.
  • 6. Destination Socket = 10.0.0.2 : 80 IP Address – Choose network 20.0.0.0 10.0.0.0 30.0.0.0 40.0.0.0
  • 7. Destination Socket = 10.0.0.2 : 80 IP Address -> MAC Address – Locate the specific system 10.0.0.1 10.0.0.2
  • 8. Port Number – Process specific Port 10000 Port 11000 Port 120000
  • 9. Understanding Ports OutLook AVG Gmail YM Express Update Port 1 Port 2 Port 3 Port 4 Transport Layer Packet Port num data Network layer
  • 10.  Thus virtually, sockets are a connection between the two processes in different systems.  Eg : Let the socket pairs be  10.0.0.1 : 80 and 20.0.0.1 : 2000  192.168.21.10 : 3000 and 192.168.100.1 : 6000
  • 11. Networking Basics – the larger picture  Applications Layer  Standard apps  HTTP TCP STACK  FTP  Telnet Application  User apps (http,ftp,telnet,…)  Transport Layer Transport  TCP (TCP, UDP,..)  UDP Network  Network Layer (IP,..)  IP  Link Layer Link (device driver,..)  Device drivers
  • 12. Network Basics - Where are these sockets?  Applications Layer  Standard apps  HTTP TCP STACK  FTP  Telnet Application  User apps (http,ftp,telnet,…)  Programming Interface: Sockets  SOCKETS Transport  Transport Layer (TCP, UDP,..)  TCP  UDP Network (IP,..)  Network Layer Link  IP  Link Layer (device driver,..)  Device drivers
  • 13. Now into Socket programming..
  • 14. Socket Programming with TCP  Server starts first..  Server Process must be running first  Server must have created a socket which welcomes client’s connection. (Welcoming socket)  Client contacts server by..  Creating Client local TCP socket  Specify IP Address and port number of server process.  When Client socket is created, the connection is established.  When connection is established, server creates a new socket (Connection Socket) to communicate with that client and the Welcoming socket is once again waiting for connections for other clients.
  • 15. Client/Server Socket Interaction in TCP Server create socket, port=x, for incoming request: welcomeSocket = ServerSocket() Client wait for incoming TCP create socket, connection request connection setup connect to hostid, port=x connectionSocket = clientSocket = welcomeSocket.accept() Socket() send request using read request from clientSocket connectionSocket write reply to connectionSocket read reply from connectionSocket close connectionSocket close clientSocket
  • 16. Step 1 : Connection request port Server Client Step 2 : port Server port Client port Connection
  • 17. Types of Sockets in TCP  ServerSocket – the socket used by servers  Socket – Socket used by clients  Create a ServerSocket in the server and make it to wait for connections from Sockets from other clients
  • 18. The concept of Streams Client output Server input stream stream Client Server socket socket Client input Server output stream stream
  • 19. Socket Programming with UDP  No Connection between client and server.  No handshaking  The sender has to explicitly mention the IP address and the port of the destination.  The server should extract the IP Address of the datagram everytime.  Uses DatagramSocket.
  • 20. Client/server socket interaction: UDP Server Client create socket, create socket, port=x, for clientSocket = incoming request: DatagramSocket() serverSocket = DatagramSocket() Create, address (hostid, port=x), send datagram request using clientSocket read request from serverSocket write reply to serverSocket read reply from specifying client clientSocket host address, port number close clientSocket
  • 22. Conclusion  Socket Programming is very easy in Java.  Usually each and every socket is handled by a separate thread in real-time client/server environments.