SlideShare a Scribd company logo
3
Most read
4
Most read
7
Most read
R.Pavithra
Department of CS&IT
Nadar saraswathi college of
arts & science, theni.
contents
 Introduction Sockets
 Server Socket And Client Socket
 Tcp/ Ip In Java
 Types Of Sockets In Java
 Tcp/Ip Server Socket
 Tcp/Ip Client Socket
 Conculsion
Introduction sockets
 The term socket programming refers to writing programs
that execute across multiple computers in which the
devices are all connected to each other using a network.
 There are two communication protocols that one can use
for socket programming :User datagram
protocol(UDP)and Transfer control protocol(TCP)
Server socket and client socket
 A server socket keeps on listening to any incoming
connections from any of the clients.
 When you create a client socket, you simply specify the
server address and port. You never bind or listen using a
client socket.
 You simply connect a client socket . On the other hand
you dont connect using a server socket.
TCP/IP in java
 Accessing TCP/IP from java is Straightforward. The
main functionality is in the following classes:
 Java.net.InetAddress: Represents an IP address( either
IPV4or IPV6) and has methods for performing DNS
lookup( next slide).
 Java.net.Socket: Represents a TCP socket.
 Java.net.ServerSocket: Represents a server socket which
is capable of waiting for requests from clients.
Types of sockets in java
 Java provides three different types of sockets connection-
oriented(TCP) sockets are implemented with the socket
class.
 Connectionless(UDP) sockets uses the Datagram Socket
class. A third type is the Multicast Socket class, which is a
subclass of the datagram Socket class.
 Server
 client
TCP/IP SERVER SOCKETS
 A socket in java is one endpoint of two-way
communication link between two programs runnning on
the network.
 A socket is bound to a port number so that the TCP layer
can identify the application that data is destined to be sent
to .
 An endpoint is a combination of an IP address and a port
number.
continue
syntax descriptions
Server Socket( int port ) throws
IOException
Creates server socket on the specified
port with a queue length of 50
Server Socket( int port, int maxQueue)
Throws IOException
Creates a server socket on the specified
port with a maximum queue length of
maxQueue.
Server Socket( it port, int
maxQueue,inetAddress local Address)
Throws IOException
Creates a server socket on the specified
port with a maximum queue length of
maxQueue, on a multihomed host, local
Address specifies the ip address to which
this socket binds.
Example program for server socket
Import java.net.*;
Import java.io.*;
Public class serverside{
Private Socket socket=null;
Private serversocket =null;
Sop(“server started”);
Sop(“waiting for client”);
Socket=server.accept();
Sop(“client accepted”);
In=new dataintputstream (
New bufferedinputstream(socket.getInputstream()));
String line=””;
While(!line.equals(‘over”)){
Try{
Line=input.readline();
Out.writeUTF(line);}
Catch(IOException i){
Sop(i);}}
Sop(“closing connection”);
Socket.close();
In.close();}
Catch(IOException i){
Sop(i);}}
Public static void main(stringargs[]){
Server server =new server(5000);}}
TCP/IP CLIENT SOCKET
 TCP/IP client sockets. TCP/IP sockets are used to
implement reliable, bidirectional, persistent, point-to-
point, stream-based connections between hosts on the
internet. A socket can be used to connect java’s I/O system
to other programs that may reside either on the local
machine or on any other machine on the internet.
Tcp/ip server sockets
syntax description
InetAddress getInetAddress() Returns the InetAdd associated with
the socket object .It returns null If
the socket is not connected.
Intgetport()
Returns the remote port to which
the invoking socket object is
connected . It returns O if the
socket is not connected.
Intgetlocalport() Returns the local port to which the
invoking socket object is bound. It
returns -1if the socket is not bound.
Continue……
 You can gain access I/P and O/P streams associated with
socket by use of
 Get I/P stream()
 Get O/P stream()
 Each can throw an IOException if the socket has been
invalidated by a loss of connections.
syntax description
inputstream getI/Pstream()
Throws IOException
Returns the inputs stream
associated with the invoking
socket
Outputstream get O/P
stream() throws IOException
Returns the outputs stream
associated with the invoking
socket
Other method
Syntax Description
“including connect()” Which allows you to specify a new
connections
“is connected()” Which returns true if the socket is
connected to server.
“is bound()” Which returns if the socket is bound to
an address
“is closed()” Which returns true if the socket is
closed.
Example program client socket
Import java.net.*;
Import java.io.*;
Public class clientprogram{
Private Socket socket=null;
Private datainputstream input=null;
Private dataoutputstream output=null;
Public client(string address,int port){
Try{
Socket =new socket(address,port);
Sop(“connected”);
Input=new datainputstream(system.in);
Out=new dataoutputstream(socket.getoutputstream());}
Catch(unknownHostException u){
Sop(u);}
Catch(IOException i){
Sop(i);}
String line=””;
While(!line.equals(‘over”)){
Try{
Line=input.readline();
Out.writeUTF(line);}
Catch(IOException i){
Sop(i);}}
Try
{input.close();
Out.close();
Socket.close();}
Catch(IOException i){
Sop(i);}}
Public static void n=amin(stringargs[]){
Client client =new client(127.0.0.1”,5000);}}
conculsion
 Programing client and server applications in
java is fun and challenging.
 Programming socket programming injava is
much easier than doing it in other languages
such as C.
 Key words:
 Client,servers,TCP/IP,port,number,sockets, java
sockets.

More Related Content

PPTX
Latest trends in information technology
PPTX
Css types internal, external and inline (1)
PPTX
Blood Bank Management System (including UML diagrams)
PDF
Sample_report_for_MINI_PROJECT.docx (1).pdf
DOCX
Notes of Software engineering and Project Management
PPTX
Introduction Wireless Technology
PDF
5 Leadership Lessons from Nelson Mandela
PPTX
Types of Machine Learning
Latest trends in information technology
Css types internal, external and inline (1)
Blood Bank Management System (including UML diagrams)
Sample_report_for_MINI_PROJECT.docx (1).pdf
Notes of Software engineering and Project Management
Introduction Wireless Technology
5 Leadership Lessons from Nelson Mandela
Types of Machine Learning

What's hot (20)

PPTX
Transport layer
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPT
Unit 1 - Introduction to Software Engineering.ppt
PPTX
10 implementing subprograms
PPTX
Routing algorithm
PPT
Java Networking
PDF
Mobile transportlayer
PPTX
Link state routing protocol
PDF
Google App Engine
PPTX
PPTX
Transport layer protocol
PPTX
Project scheduling and tracking
PPTX
Classification of routing protocols
PPT
Coupling and cohesion
PPTX
What Is User Datagram Protocol?
PDF
Java threads
PPTX
Session tracking in servlets
PPTX
Timestamp protocols
PPTX
Point to-point protocol (ppp)
PPT
Distance vector routing
Transport layer
Type Checking(Compiler Design) #ShareThisIfYouLike
Unit 1 - Introduction to Software Engineering.ppt
10 implementing subprograms
Routing algorithm
Java Networking
Mobile transportlayer
Link state routing protocol
Google App Engine
Transport layer protocol
Project scheduling and tracking
Classification of routing protocols
Coupling and cohesion
What Is User Datagram Protocol?
Java threads
Session tracking in servlets
Timestamp protocols
Point to-point protocol (ppp)
Distance vector routing
Ad

Similar to Tcp/ip server sockets (20)

PPT
Unit 8 Java
PPT
Network programming in Java
PPT
Socket Programming - nitish nagar
PPT
Sockets
PPT
Socket Programming it-slideshares.blogspot.com
PPTX
PPT
Md13 networking
PPTX
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
PPT
Java Networking
PPT
Basic Networking in Java
PPTX
PPTX
Network programming in java - PPT
DOCX
Mail Server Project Report
PPTX
Java networking
PPTX
PPT
Java networking
PPT
Socket programming
PPT
Socket programming
PPT
Network programming in Java
DOC
Unit 8 Java
Network programming in Java
Socket Programming - nitish nagar
Sockets
Socket Programming it-slideshares.blogspot.com
Md13 networking
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Java Networking
Basic Networking in Java
Network programming in java - PPT
Mail Server Project Report
Java networking
Java networking
Socket programming
Socket programming
Network programming in Java
Ad

More from rajshreemuthiah (20)

PPTX
PPTX
PPTX
PPTX
polymorphism
PPTX
solutions and understanding text analytics
PPTX
interface
PPTX
Testing &ampdebugging
PPTX
concurrency control
PPTX
Education
PPTX
Formal verification
PPTX
Transaction management
PPTX
Multi thread
PPTX
System testing
PPTX
software maintenance
PPTX
exception handling
PPTX
e governance
PPTX
recovery management
PPTX
Implementing polymorphism
PPSX
Buffer managements
PPTX
os linux
polymorphism
solutions and understanding text analytics
interface
Testing &ampdebugging
concurrency control
Education
Formal verification
Transaction management
Multi thread
System testing
software maintenance
exception handling
e governance
recovery management
Implementing polymorphism
Buffer managements
os linux

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
PPTX
CroxyProxy Instagram Access id login.pptx
PDF
Modernizing your data center with Dell and AMD
PDF
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
PDF
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reimagining Insurance: Connected Data for Confident Decisions.pdf
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Dell Pro 14 Plus: Be better prepared for what’s coming
PPTX
Belt and Road Supply Chain Finance Blockchain Solution
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Transforming Manufacturing operations through Intelligent Integrations
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
CIFDAQ's Teaching Thursday: Moving Averages Made Simple
GamePlan Trading System Review: Professional Trader's Honest Take
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
CroxyProxy Instagram Access id login.pptx
Modernizing your data center with Dell and AMD
ai-archetype-understanding-the-personality-of-agentic-ai.pdf
CIFDAQ's Token Spotlight: SKY - A Forgotten Giant's Comeback?
Chapter 3 Spatial Domain Image Processing.pdf
Reimagining Insurance: Connected Data for Confident Decisions.pdf
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Web Security: Login Bypass, SQLi, CSRF & XSS.pptx
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Dell Pro 14 Plus: Be better prepared for what’s coming
Belt and Road Supply Chain Finance Blockchain Solution
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Transforming Manufacturing operations through Intelligent Integrations

Tcp/ip server sockets

  • 1. R.Pavithra Department of CS&IT Nadar saraswathi college of arts & science, theni.
  • 2. contents  Introduction Sockets  Server Socket And Client Socket  Tcp/ Ip In Java  Types Of Sockets In Java  Tcp/Ip Server Socket  Tcp/Ip Client Socket  Conculsion
  • 3. Introduction sockets  The term socket programming refers to writing programs that execute across multiple computers in which the devices are all connected to each other using a network.  There are two communication protocols that one can use for socket programming :User datagram protocol(UDP)and Transfer control protocol(TCP)
  • 4. Server socket and client socket  A server socket keeps on listening to any incoming connections from any of the clients.  When you create a client socket, you simply specify the server address and port. You never bind or listen using a client socket.  You simply connect a client socket . On the other hand you dont connect using a server socket.
  • 5. TCP/IP in java  Accessing TCP/IP from java is Straightforward. The main functionality is in the following classes:  Java.net.InetAddress: Represents an IP address( either IPV4or IPV6) and has methods for performing DNS lookup( next slide).  Java.net.Socket: Represents a TCP socket.  Java.net.ServerSocket: Represents a server socket which is capable of waiting for requests from clients.
  • 6. Types of sockets in java  Java provides three different types of sockets connection- oriented(TCP) sockets are implemented with the socket class.  Connectionless(UDP) sockets uses the Datagram Socket class. A third type is the Multicast Socket class, which is a subclass of the datagram Socket class.  Server  client
  • 7. TCP/IP SERVER SOCKETS  A socket in java is one endpoint of two-way communication link between two programs runnning on the network.  A socket is bound to a port number so that the TCP layer can identify the application that data is destined to be sent to .  An endpoint is a combination of an IP address and a port number.
  • 8. continue syntax descriptions Server Socket( int port ) throws IOException Creates server socket on the specified port with a queue length of 50 Server Socket( int port, int maxQueue) Throws IOException Creates a server socket on the specified port with a maximum queue length of maxQueue. Server Socket( it port, int maxQueue,inetAddress local Address) Throws IOException Creates a server socket on the specified port with a maximum queue length of maxQueue, on a multihomed host, local Address specifies the ip address to which this socket binds.
  • 9. Example program for server socket Import java.net.*; Import java.io.*; Public class serverside{ Private Socket socket=null; Private serversocket =null; Sop(“server started”); Sop(“waiting for client”); Socket=server.accept(); Sop(“client accepted”); In=new dataintputstream ( New bufferedinputstream(socket.getInputstream())); String line=””; While(!line.equals(‘over”)){
  • 11. TCP/IP CLIENT SOCKET  TCP/IP client sockets. TCP/IP sockets are used to implement reliable, bidirectional, persistent, point-to- point, stream-based connections between hosts on the internet. A socket can be used to connect java’s I/O system to other programs that may reside either on the local machine or on any other machine on the internet.
  • 13. syntax description InetAddress getInetAddress() Returns the InetAdd associated with the socket object .It returns null If the socket is not connected. Intgetport() Returns the remote port to which the invoking socket object is connected . It returns O if the socket is not connected. Intgetlocalport() Returns the local port to which the invoking socket object is bound. It returns -1if the socket is not bound.
  • 14. Continue……  You can gain access I/P and O/P streams associated with socket by use of  Get I/P stream()  Get O/P stream()  Each can throw an IOException if the socket has been invalidated by a loss of connections. syntax description inputstream getI/Pstream() Throws IOException Returns the inputs stream associated with the invoking socket Outputstream get O/P stream() throws IOException Returns the outputs stream associated with the invoking socket
  • 15. Other method Syntax Description “including connect()” Which allows you to specify a new connections “is connected()” Which returns true if the socket is connected to server. “is bound()” Which returns if the socket is bound to an address “is closed()” Which returns true if the socket is closed.
  • 16. Example program client socket Import java.net.*; Import java.io.*; Public class clientprogram{ Private Socket socket=null; Private datainputstream input=null; Private dataoutputstream output=null; Public client(string address,int port){ Try{ Socket =new socket(address,port); Sop(“connected”); Input=new datainputstream(system.in); Out=new dataoutputstream(socket.getoutputstream());} Catch(unknownHostException u){
  • 17. Sop(u);} Catch(IOException i){ Sop(i);} String line=””; While(!line.equals(‘over”)){ Try{ Line=input.readline(); Out.writeUTF(line);} Catch(IOException i){ Sop(i);}} Try {input.close(); Out.close(); Socket.close();} Catch(IOException i){ Sop(i);}} Public static void n=amin(stringargs[]){ Client client =new client(127.0.0.1”,5000);}}
  • 18. conculsion  Programing client and server applications in java is fun and challenging.  Programming socket programming injava is much easier than doing it in other languages such as C.  Key words:  Client,servers,TCP/IP,port,number,sockets, java sockets.