If socket is representing client side and serversocket representing server side, why socket.read reads the data from serverside...Im really confused ...make me clear pls...?
ServerSocket is again a Socket with additional features of server endpoint. The server features includes listening to the port and accepting an incoming connection etc...
why socket.read reads the data from serverside
Because it is reading the data sent by the server through the network, it is not reading directly the server filesystem or resouces ( db , ram or anything like that ) it is reading the data that was already processed by the ServerSocket.
Think about the Socket as your web browser and the ServerSocket as the remote webserver.
When you request an image, page, etc, the webserver ( The ServerSocket ) writes the bytes to the client, in turn the client has to read them ( to know what the webserver sent right? ) and process them by displaying them to the final user.
The same happend with ServerSocket/Socket but at a lower level. The socket reads information from the ServerSocket.
Does it make sense?
Take a look at http://java.sun.com/docs/books/tutorial/networking/sockets/
socket is from client side and serversocket is from server side
Thanks Sunil Kumar Sahoo