What is the difference between Socket and ServerSocket?

前端 未结 9 1332
遇见更好的自我
遇见更好的自我 2021-02-01 02:10

If Socket represents client side and ServerSocket represents server side, why Socket.read reads the data from server side? I\'m really con

相关标签:
9条回答
  • 2021-02-01 02:41

    Because it's reading what has been sent to you by the server.

    0 讨论(0)
  • 2021-02-01 02:43

    ServerSocket is created to bind to a port and listen for a connect from a client. So, a server just waits for a conversation and doesn't start one.

    ClientSocket is created to connect to a listening server. The client initiates the connection.

    Example: Think of an inbound call center as an example. These services are servers. They don't initiate a call but wait for a call to come in from clients. Once the calls are in, they can engage in a two way conversation.

    0 讨论(0)
  • 2021-02-01 02:44

    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?

    0 讨论(0)
提交回复
热议问题