Java - networking ServerSocket Class Methdos

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

the steps when establishing a TCP connection between two computers using sockets

the server instantiates a ServerSocket object, denoting which port number communication is to occur on the server invokes the accept() method of the Server Socket class. This method waits until a client connects to the server on the given port after the server is waiting, a client instantiates a Socket object, specifying the server name and port number to connect to. the constructor of the Socket class attempts to connect the client to the specified server and port number. on the server side, the accept() method returns a reference to a new socket on the server that is connected to the client's socket

Socket

A communication path between two remote programs

public ServerSocket(int port) throws IOException

Attempts to create a server socket bound to the specified port. An exception occurs if the port is already bound by another application

public void bind(SocketAddress host, int backlog)

Binds the socket to the specified server and port in the SocketAddress object. Use this method if you instantiated the ServerSocket using the no-argument constructor.

public ServerSocket() throws IOException

Creates an unbound server socket. When using this constructor, use the bind() method when you are ready to bind the server socket

public int getLocalPort()

Returns the port that the server socket is listening on. This method is useful if you passed in 0 as the port number in a constructor and let the server find a port for you.

public void setSoTimeout(int timeout)

Sets the time-out value for how long the server socket waits for a client during the accept().

public ServerSocket(int port, int backlog, InetAddress address) throws IOException

Similar to the previous constructor, the InetAddress parameter specifies the local IP address to bind to. The InetAddress is used for servers that may have multiple IP addresses, allowing the server to specify which of its IP addresses to accept client requests on

public ServerSocket(int port, int backlog) throws IOException

Similar to the previous constructor, the backlog parameter specifies how many incoming clients to store in a wait queue.

public Socket accept() throws IOException

Waits for an incoming client. This method blocks until either a client connects to the server on the specified port or the socket times out, assuming that the time-out value has been set using the setSoTimeout() method. Otherwise, this method blocks indefinitely


Kaugnay na mga set ng pag-aaral

Chapter 1 Quiz: What is Philosophy?

View Set

Mosby questions Quiz 401 Critical Respiratory

View Set

The Muscular System Chapter 10 Review

View Set