SlideShare a Scribd company logo
14
Most read
19
Most read
22
Most read
Socket programming in javaNarendranThangarajan,@naren_live,II Year, BE, CSE,SSN College of Engg, Chennai.
What started it all..Internet  has emerged as a global ubiquitous media for communicationIt 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 ApplicationsThe Web Service is provided by the server and the clients use these servicesClientRequestServerNetworkResultClient machineServer machineA client, A server, and networkThis is where sockets come in !!
SocketsIntroduced 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 : 80IP Address – Choose network20.0.0.030.0.0.010.0.0.040.0.0.0
IP Address -> MAC Address – Locate the 						specific systemDestination Socket = 10.0.0.2 : 8010.0.0.110.0.0.2
Port Number – Process specificPort 10000Port 11000Port 120000
Understanding PortsGmailYMAVG UpdateOutLookExpressPort 1Port 2Port 3Port 4Transport LayerPacketPort numdataNetwork layer
Thus virtually, sockets are a connection between the two processes in different systems.Eg : Let the socket pairs be10.0.0.1 : 80 and 20.0.0.1 : 2000192.168.21.10 : 3000 and 192.168.100.1 : 6000
Networking Basics – the larger pictureApplications Layer
Standard apps
HTTP
FTP
Telnet
User apps
Transport Layer
TCP
UDP
Network Layer
IP
Link Layer
Device driversTCP STACKApplication(http,ftp,telnet,…)Transport(TCP, UDP,..)Network(IP,..)Link(device driver,..)

More Related Content

PPTX
Java socket programming
PPTX
Network programming in java - PPT
PPT
Network programming in Java
PPTX
Tcp/ip server sockets
PPT
Java Networking
PDF
COMPUTER NETWORKS NOTES.pdf
PDF
Unit-4 networking basics in java
PPTX
Message and Stream Oriented Communication
Java socket programming
Network programming in java - PPT
Network programming in Java
Tcp/ip server sockets
Java Networking
COMPUTER NETWORKS NOTES.pdf
Unit-4 networking basics in java
Message and Stream Oriented Communication

What's hot (20)

PPTX
Java - Sockets
PDF
Socket programming using java
PPT
Servlet life cycle
PDF
Servlet and servlet life cycle
PPS
Java rmi
PPS
Java Exception handling
PPT
Thread model in java
PPT
Java multi threading
PPTX
Networking in Java
PPTX
Java RMI
PPTX
Symbol Table
PPTX
Android Services
PPTX
JAVA AWT
PDF
Remote Method Invocation (RMI)
PPTX
Multithreading in java
PPTX
Java servlets
PPTX
Constructor in java
PPT
Java Servlets
PPTX
Jdbc ppt
Java - Sockets
Socket programming using java
Servlet life cycle
Servlet and servlet life cycle
Java rmi
Java Exception handling
Thread model in java
Java multi threading
Networking in Java
Java RMI
Symbol Table
Android Services
JAVA AWT
Remote Method Invocation (RMI)
Multithreading in java
Java servlets
Constructor in java
Java Servlets
Jdbc ppt
Ad

Similar to Socket programming in Java (PPTX) (20)

PPTX
Java Network Programming.pptx
PPT
Socket Programming in Java.ppt yeh haii
PPTX
5_6278455688045789623.pptx
PPT
Network Programming in Java
PPT
Sockets
PPTX
Socket programming
PPT
Networking in java
PPT
Socket Programming - nitish nagar
PDF
Socket Programming
PPTX
PDF
28 networking
PDF
JavaSockets-Session10 New York university.pdf
PPT
Socket programming
PDF
Chap 1 Network Theory & Java Overview
PPT
Network programming in Java
PPT
Networking Java Socket Programming
DOCX
Final networks lab manual
PDF
Network Sockets
PDF
Sockets
PPT
Unit 8 Java
Java Network Programming.pptx
Socket Programming in Java.ppt yeh haii
5_6278455688045789623.pptx
Network Programming in Java
Sockets
Socket programming
Networking in java
Socket Programming - nitish nagar
Socket Programming
28 networking
JavaSockets-Session10 New York university.pdf
Socket programming
Chap 1 Network Theory & Java Overview
Network programming in Java
Networking Java Socket Programming
Final networks lab manual
Network Sockets
Sockets
Unit 8 Java
Ad

More from UC San Diego (19)

PDF
A primer on network devices
PDF
Datacenter traffic demand characterization
PDF
Smart Homes, Buildings and Internet-of-things
PDF
Social Networks analysis to characterize HIV at-risk populations - Progress a...
PDF
eyeTalk - A system for helping people affected by motor neuron problems
PDF
Pirc net poster
PDF
Ajaxism
PDF
Basic terminologies for a developer
PDF
Fields in computer science
PDF
Understanding computer networks
PDF
FOSS Introduction
PDF
Network Programming with Umit project
PDF
Introduction to Python
PDF
Airline reservation system db design
PDF
Workshop on Network Security
PDF
Routing basics
PDF
Technology Quiz
PDF
Android application development
PDF
Pervasive Web Application Architecture
A primer on network devices
Datacenter traffic demand characterization
Smart Homes, Buildings and Internet-of-things
Social Networks analysis to characterize HIV at-risk populations - Progress a...
eyeTalk - A system for helping people affected by motor neuron problems
Pirc net poster
Ajaxism
Basic terminologies for a developer
Fields in computer science
Understanding computer networks
FOSS Introduction
Network Programming with Umit project
Introduction to Python
Airline reservation system db design
Workshop on Network Security
Routing basics
Technology Quiz
Android application development
Pervasive Web Application Architecture

Recently uploaded (20)

PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Open folder Downloads.pdf yes yes ges yes
PDF
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
English Language Teaching from Post-.pdf
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Cell Structure & Organelles in detailed.
PPTX
Pharma ospi slides which help in ospi learning
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Open folder Downloads.pdf yes yes ges yes
Piense y hagase Rico - Napoleon Hill Ccesa007.pdf
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
English Language Teaching from Post-.pdf
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Pre independence Education in Inndia.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Cell Structure & Organelles in detailed.
Pharma ospi slides which help in ospi learning
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
Anesthesia in Laparoscopic Surgery in India
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
Revamp in MTO Odoo 18 Inventory - Odoo Slides
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx

Socket programming in Java (PPTX)

  • 1. Socket programming in javaNarendranThangarajan,@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 communicationIt 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 ApplicationsThe Web Service is provided by the server and the clients use these servicesClientRequestServerNetworkResultClient machineServer machineA client, A server, and networkThis is where sockets come in !!
  • 4. SocketsIntroduced 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 : 80IP Address – Choose network20.0.0.030.0.0.010.0.0.040.0.0.0
  • 7. IP Address -> MAC Address – Locate the specific systemDestination Socket = 10.0.0.2 : 8010.0.0.110.0.0.2
  • 8. Port Number – Process specificPort 10000Port 11000Port 120000
  • 9. Understanding PortsGmailYMAVG UpdateOutLookExpressPort 1Port 2Port 3Port 4Transport LayerPacketPort numdataNetwork layer
  • 10. Thus virtually, sockets are a connection between the two processes in different systems.Eg : Let the socket pairs be10.0.0.1 : 80 and 20.0.0.1 : 2000192.168.21.10 : 3000 and 192.168.100.1 : 6000
  • 11. Networking Basics – the larger pictureApplications Layer
  • 13. HTTP
  • 14. FTP
  • 18. TCP
  • 19. UDP
  • 21. IP
  • 23. Device driversTCP STACKApplication(http,ftp,telnet,…)Transport(TCP, UDP,..)Network(IP,..)Link(device driver,..)
  • 24. Network Basics - Where are these sockets?Applications Layer
  • 26. HTTP
  • 27. FTP
  • 33. TCP
  • 34. UDP
  • 36. IP
  • 39. Now into Socket programming..
  • 40. Socket Programming with TCPServer starts first..Server Process must be running firstServer must have created a socket which welcomes client’s connection. (Welcoming socket)Client contacts server by..Creating Client local TCP socketSpecify 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=xcreate socket,port=x, forincoming request:clientSocket = Socket()welcomeSocket = ServerSocket()wait for incomingconnection requestconnectionSocket =welcomeSocket.accept()send request usingclientSocketread request fromconnectionSocketwrite reply toconnectionSocketread reply fromconnectionSocketcloseconnectionSocketcloseclientSocketClient/Server Socket Interaction in TCPServerClientTCP connection setup
  • 42. Step 1 :Step 2 :ServerportServerConnection requestportClientportportClientConnection
  • 43. Types of Sockets in TCPServerSocket – the socket used by serversSocket – Socket used by clientsCreate a ServerSocket in the server and make it to wait for connections from Sockets from other clients
  • 44. The concept of StreamsClient output streamServer input streamServer socketClient socketClient input streamServer output stream
  • 45. Socket Programming with UDPNo Connection between client and server.No handshakingThe 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. Clientcreate socket,port=x, forincoming request:serverSocket = DatagramSocket()create socket,clientSocket = DatagramSocket()Create, address (hostid, port=x),send datagram request using clientSocketread request fromserverSocketwrite reply toserverSocketspecifying clienthost address,port numberread reply fromclientSocketcloseclientSocketClient/server socket interaction: UDPServer
  • 48. ConclusionSocket Programming is very easy in Java.Usually each and every socket is handled by a separate thread in real-time client/server environments.