SlideShare a Scribd company logo
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.
Ad

More Related Content

What's hot (20)

ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOL
Shashank Rustagi
 
Interface specification
Interface specificationInterface specification
Interface specification
maliksiddique1
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
Dattatray Gandhmal
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Context model
Context modelContext model
Context model
Ubaid423
 
Congestion control
Congestion controlCongestion control
Congestion control
Aman Jaiswal
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
Swati Chauhan
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
Hitesh Mohapatra
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
shivli0769
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
Bushra M
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
SOMNATHMORE2
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Network Layer,Computer Networks
Network Layer,Computer NetworksNetwork Layer,Computer Networks
Network Layer,Computer Networks
guesta81d4b
 
Telnet
TelnetTelnet
Telnet
Jishnu Pradeep
 
Artificial Intelligence - Hill climbing.
Artificial Intelligence - Hill climbing.Artificial Intelligence - Hill climbing.
Artificial Intelligence - Hill climbing.
StephenTec
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
Acad
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
Shehara Abeythunga
 
ELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOLELEMENTS OF TRANSPORT PROTOCOL
ELEMENTS OF TRANSPORT PROTOCOL
Shashank Rustagi
 
Interface specification
Interface specificationInterface specification
Interface specification
maliksiddique1
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Context model
Context modelContext model
Context model
Ubaid423
 
Congestion control
Congestion controlCongestion control
Congestion control
Aman Jaiswal
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
Symbol table management and error handling in compiler design
Symbol table management and error handling in compiler designSymbol table management and error handling in compiler design
Symbol table management and error handling in compiler design
Swati Chauhan
 
State Space Representation and Search
State Space Representation and SearchState Space Representation and Search
State Space Representation and Search
Hitesh Mohapatra
 
Token, Pattern and Lexeme
Token, Pattern and LexemeToken, Pattern and Lexeme
Token, Pattern and Lexeme
A. S. M. Shafi
 
Distributed computing
Distributed computingDistributed computing
Distributed computing
shivli0769
 
Routing algorithm
Routing algorithmRouting algorithm
Routing algorithm
Bushra M
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
SOMNATHMORE2
 
Network Layer,Computer Networks
Network Layer,Computer NetworksNetwork Layer,Computer Networks
Network Layer,Computer Networks
guesta81d4b
 
Artificial Intelligence - Hill climbing.
Artificial Intelligence - Hill climbing.Artificial Intelligence - Hill climbing.
Artificial Intelligence - Hill climbing.
StephenTec
 
Network Layer design Issues.pptx
Network Layer design Issues.pptxNetwork Layer design Issues.pptx
Network Layer design Issues.pptx
Acad
 
Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking Sum of subsets problem by backtracking 
Sum of subsets problem by backtracking 
Hasanain Alshadoodee
 

Similar to Tcp/ip server sockets (20)

Unit 8 Java
Unit 8 JavaUnit 8 Java
Unit 8 Java
arnold 7490
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Sockets
SocketsSockets
Sockets
sivindia
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
phanleson
 
Java 1
Java 1Java 1
Java 1
VidyaVarshini3
 
Md13 networking
Md13 networkingMd13 networking
Md13 networking
Rakesh Madugula
 
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
KuntalVasoya
 
Java Networking
Java NetworkingJava Networking
Java Networking
Ankit Desai
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
suraj pandey
 
A.java
A.javaA.java
A.java
JahnaviBhagat
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
Kavita Sharma
 
Java networking
Java networkingJava networking
Java networking
ssuser3a47cb
 
Java
JavaJava
Java
Subha Selvam
 
Java networking
Java networkingJava networking
Java networking
Arati Gadgil
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Socket
SocketSocket
Socket
Amandeep Kaur
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Socket Programming - nitish nagar
Socket Programming - nitish nagarSocket Programming - nitish nagar
Socket Programming - nitish nagar
Nitish Nagar
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
phanleson
 
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
Advanced Java Programming: Introduction and Overview of Java Networking 1. In...
KuntalVasoya
 
Basic Networking in Java
Basic Networking in JavaBasic Networking in Java
Basic Networking in Java
suraj pandey
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 
Mail Server Project Report
Mail Server Project ReportMail Server Project Report
Mail Server Project Report
Kavita Sharma
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Ad

More from rajshreemuthiah (20)

oracle
oracleoracle
oracle
rajshreemuthiah
 
quality
qualityquality
quality
rajshreemuthiah
 
bigdata
bigdatabigdata
bigdata
rajshreemuthiah
 
polymorphism
polymorphismpolymorphism
polymorphism
rajshreemuthiah
 
solutions and understanding text analytics
solutions and understanding text analyticssolutions and understanding text analytics
solutions and understanding text analytics
rajshreemuthiah
 
interface
interfaceinterface
interface
rajshreemuthiah
 
Testing &ampdebugging
Testing &ampdebuggingTesting &ampdebugging
Testing &ampdebugging
rajshreemuthiah
 
concurrency control
concurrency controlconcurrency control
concurrency control
rajshreemuthiah
 
Education
EducationEducation
Education
rajshreemuthiah
 
Formal verification
Formal verificationFormal verification
Formal verification
rajshreemuthiah
 
Transaction management
Transaction management Transaction management
Transaction management
rajshreemuthiah
 
Multi thread
Multi threadMulti thread
Multi thread
rajshreemuthiah
 
System testing
System testingSystem testing
System testing
rajshreemuthiah
 
software maintenance
software maintenancesoftware maintenance
software maintenance
rajshreemuthiah
 
exception handling
exception handlingexception handling
exception handling
rajshreemuthiah
 
e governance
e governancee governance
e governance
rajshreemuthiah
 
recovery management
recovery managementrecovery management
recovery management
rajshreemuthiah
 
Implementing polymorphism
Implementing polymorphismImplementing polymorphism
Implementing polymorphism
rajshreemuthiah
 
Buffer managements
Buffer managementsBuffer managements
Buffer managements
rajshreemuthiah
 
os linux
os linuxos linux
os linux
rajshreemuthiah
 
Ad

Recently uploaded (20)

Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
Com fer un pla de gestió de dades amb l'eiNa DMP (en anglès)
CSUC - Consorci de Serveis Universitaris de Catalunya
 
Build With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdfBuild With AI - In Person Session Slides.pdf
Build With AI - In Person Session Slides.pdf
Google Developer Group - Harare
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptxTop 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
Top 5 Benefits of Using Molybdenum Rods in Industrial Applications.pptx
mkubeusa
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
machines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdfmachines-for-woodworking-shops-en-compressed.pdf
machines-for-woodworking-shops-en-compressed.pdf
AmirStern2
 
How to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabberHow to Install & Activate ListGrabber - eGrabber
How to Install & Activate ListGrabber - eGrabber
eGrabber
 
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
On-Device or Remote? On the Energy Efficiency of Fetching LLM-Generated Conte...
Ivano Malavolta
 
Artificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptxArtificial_Intelligence_in_Everyday_Life.pptx
Artificial_Intelligence_in_Everyday_Life.pptx
03ANMOLCHAURASIYA
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?Shoehorning dependency injection into a FP language, what does it take?
Shoehorning dependency injection into a FP language, what does it take?
Eric Torreborre
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Config 2025 presentation recap covering both days
Config 2025 presentation recap covering both daysConfig 2025 presentation recap covering both days
Config 2025 presentation recap covering both days
TrishAntoni1
 
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
RTP Over QUIC: An Interesting Opportunity Or Wasted Time?
Lorenzo Miniero
 
Unlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web AppsUnlocking Generative AI in your Web Apps
Unlocking Generative AI in your Web Apps
Maximiliano Firtman
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptxDevOpsDays SLC - Platform Engineers are Product Managers.pptx
DevOpsDays SLC - Platform Engineers are Product Managers.pptx
Justin Reock
 
Building the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdfBuilding the Customer Identity Community, Together.pdf
Building the Customer Identity Community, Together.pdf
Cheryl Hung
 

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.
  翻译: