Socket-Programming in Java
Socket-Programming in Java
Outline
Introduction A step to socket programming - Protocol - IP address - Port Number Client Socket Server Socket Conclusion
Device Network
.
Basic Concept
Socket programming requires three things viz. Hardware (H/W)-router, repeaters & switch Medium- wire based & wireless
Socket
Socket is one of end point of two way communication. Socket =Protocol+Ip Address+ Port Number.
Protocol
Protocol Set of rule for communication. Protocol-http,ftp,smtp. TCP-Transmission Control Protocol. Connection Oriented. Trusted protocol. UDP-User Datagram Protocol. Connectionless . UnTrusted Protocol.
Protocol
.
High Level Protocol
Protocol
Low Level/Carrier protocol
TCP
UDP
IP Address
This is 4-byte number . Use: identify a particular device uniquely on the network.
Network Address
IP Address
Node Address
Port Number
It just a logical number. Each application have a port number. The range 0- 1023 is already reserve by high level application.
Socket Operations
Import java.net Create A Socket Class Object. Pass the IPAddress and Port Number as a argument in their Constructor . Create Proper Exception Handler.
When implementing a server you need to create a socket object from the ServerSocket in order to listen for and accept connections from clients. Import java.net Create anObject of ServerSocket class. Give a port number to their constructor. Call the accept() method by their reference.
You should always close the output and input stream before you close the socket. output.close(); input.close(); MyClient.close(); serviceSocket.close(); MyService.close();
Conclusion
Socket programming implementation is given by more technologies. Java7 technology providing high performance network stream.
Thank you