Explain how to create and use sockets in java.

Answer

Sockets are created for client and server. The ServerSocket class is used for creating sockets for server. The Socket class is used for creating sockets for client side.

After creating the sockets, these sockets are utilized for both writing and writing data onto the streams. For writing data onto the output stream using client socket, the method getOutputStream() is sent as parameter to the designated output stream object, such as DataOutputStream. For reading data from the input stream using client socket, the method getInputStream() is sent as parameter to the designated inpout stream object, such as DataInputStream.

For placing data on the server socket, the method accept() is used. The result of accept() is assigned to the client socket.

All Java Questions

Ask your interview questions on java

Write Your comment or Questions if you want the answers on java from java Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---