Socket programming in Java (PPTX)
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Socket programming in Java (PPTX)

on

  • 1,851 views

 

Statistics

Views

Total Views
1,851
Views on SlideShare
1,846
Embed Views
5

Actions

Likes
0
Downloads
34
Comments
0

2 Embeds 5

http://www.linkedin.com 4
https://www.linkedin.com 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Socket programming in Java (PPTX) Presentation Transcript

  • 1. Socket programming in java
    NarendranThangarajan,
    @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
    Request
    Server
    Network
    Result
    Client machine
    Server machine
    A client, A server, and network
    This is where sockets 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
    • 6. 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
    30.0.0.0
    10.0.0.0
    40.0.0.0
  • 7. IP Address -> MAC Address – Locate the specific system
    Destination Socket = 10.0.0.2 : 80
    10.0.0.1
    10.0.0.2
  • 8. Port Number – Process specific
    Port 10000
    Port 11000
    Port 120000
  • 9. Understanding Ports
    Gmail
    YM
    AVG
    Update
    OutLook
    Express
    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
    • 12. Standard apps
    • 13. HTTP
    • 14. FTP
    • 15. Telnet
    • 16. User apps
    • 17. Transport Layer
    • 18. TCP
    • 19. UDP
    • 20. Network Layer
    • 21. IP
    • 22. Link Layer
    • 23. Device drivers
    TCP STACK
    Application
    (http,ftp,telnet,…)
    Transport
    (TCP, UDP,..)
    Network
    (IP,..)
    Link
    (device driver,..)
  • 24. Network Basics - Where are these sockets?
    • Applications Layer
    • 25. Standard apps
    • 26. HTTP
    • 27. FTP
    • 28. Telnet
    • 29. User apps
    • 30. Programming Interface:
    • 31. SOCKETS
    • 32. Transport Layer
    • 33. TCP
    • 34. UDP
    • 35. Network Layer
    • 36. IP
    • 37. Link Layer
    • 38. Device drivers
    TCP STACK
    Application
    (http,ftp,telnet,…)
    Sockets
    Transport
    (TCP, UDP,..)
    Network
    (IP,..)
    Link
    (device driver,..)
  • 39. Now into Socket programming..
  • 40. 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.
  • 41. create socket,
    connect to hostid, port=x
    create socket,
    port=x, for
    incoming request:
    clientSocket =
    Socket()
    welcomeSocket =
    ServerSocket()
    wait for incoming
    connection request
    connectionSocket =
    welcomeSocket.accept()
    send request using
    clientSocket
    read request from
    connectionSocket
    write reply to
    connectionSocket
    read reply from
    connectionSocket
    close
    connectionSocket
    close
    clientSocket
    Client/Server Socket Interaction in TCP
    Server
    Client
    TCP
    connection setup
  • 42. Step 1 :
    Step 2 :
    Server
    port
    Server
    Connection request
    port
    Client
    port
    port
    Client
    Connection
  • 43. 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
  • 44. The concept of Streams
    Client output stream
    Server input stream
    Server socket
    Client socket
    Client input stream
    Server output stream
  • 45. 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.
  • 46. Client
    create socket,
    port=x, for
    incoming request:
    serverSocket =
    DatagramSocket()
    create socket,
    clientSocket =
    DatagramSocket()
    Create, address (hostid, port=x),
    send datagram request
    using clientSocket
    read request from
    serverSocket
    write reply to
    serverSocket
    specifying client
    host address,
    port number
    read reply from
    clientSocket
    close
    clientSocket
    Client/server socket interaction: UDP
    Server
  • 47. Coding time..
  • 48. 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.
  • 49. Queries