Your SlideShare is downloading. ×
0
Socket programming in java<br />NarendranThangarajan,<br />@naren_live,<br />II Year, BE, CSE,<br />SSN College of Engg, C...
What started it all..<br />Internet  has emerged as a global ubiquitous media for communication<br />It has changed the wa...
Client Server Applications<br />The Web Service is provided by the server <br />and the clients use these services<br />Cl...
Sockets<br />Introduced in BSD 4.1 UNIX 1981.<br />Sockets are the endpoints of any communication over the internet.<br />...
Why IP Address + Port number?<br /><ul><li>    IP Address is of the form 10.0.0.1
    Port Number can be anything from 0 to 65,535.</li></li></ul><li>Destination Socket = 10.0.0.2 : 80<br />IP Address – C...
IP Address -> MAC Address – Locate the 						specific system<br />Destination Socket = 10.0.0.2 : 80<br />10.0.0.1<br />10...
Port Number – Process specific<br />Port 10000<br />Port 11000<br />Port 120000<br />
Understanding Ports<br />Gmail<br />YM<br />AVG <br />Update<br />OutLook<br />Express<br />Port 1<br />Port 2<br />Port 3...
Thus virtually, sockets are a connection between the two processes in different systems.<br />Eg : Let the socket pairs be...
Networking Basics – the larger picture<br /><ul><li>Applications Layer
Standard apps
HTTP
FTP
Telnet
User apps
Transport Layer
TCP
UDP
Network Layer
IP
Link Layer
Device drivers</li></ul>TCP STACK<br />Application<br />(http,ftp,telnet,…)<br />Transport<br />(TCP, UDP,..)<br />Network...
Upcoming SlideShare
Loading in...5
×

Socket programming in Java (PPTX)

1,602

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,602
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
57
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Socket programming in Java (PPTX)"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×