Poll Results
No votes. Be the first one to vote.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In the context of Java, the ServerSocket class is used for implementing server-side sockets that wait for requests from clients. Several key methods are commonly used with instances of the ServerSocket class to facilitate creating a server that listens for and processes incoming connections. Here are some of these methods:
1. ServerSocket(int port): This is a constructor that creates a server socket, bound to the specified port. An application can then wait for requests to come in over the network.
2. accept(): This method listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made. It returns a new Socket object that is connected to the client.
3. close(): This method closes the server socket. Once a server socket is closed, it can no longer accept new connections.
4. setSoTimeout(int timeout): This method sets the timeout value, in milliseconds, that is used when waiting for a new connection. If the timeout expires (a value greater than 0 is set) and no connection is received, a `java.net.SocketTimeoutException` is thrown.
5. getInetAddress(): This method returns the local address of this server socket. It’s useful for obtaining the IP address on which the server is listening for incoming connections.
6. getLocalPort(): This method returns the port on which this socket is listening. It’s useful for dynamic scenarios where the operating system selects the port.
B. public socket accept ()