Skip to content

Class JutilasNet

hxs edited this page Nov 29, 2019 · 10 revisions

JutilasNet

Package jutilas.utils
File JutilasNet.java

JutilasNet is the class that contains the networking methods.
This class implements the singleton pattern, so to get the JutilasNet instance you need to use the getInstance() method.

Example: JutilasNet.getInstance().

Methods


public ServerSocket createServerSocket(int... portList)

throws NetworkExcepiton

This method create a local socket with first available.

Returns: Return the ServerSocket created.

Parameters:

  • portList, list of ports where can try to create a socket

Exceptions:

  • NetworkExcepiton, exception thrown if no ports available

Example:

ServerSocket serverSocket = JutilasNet.getInstance().createServerSocket(8080, 8585, 4545, 7070);

boolean isAvailablePort(int port)

This check if the port passed is available.

Returns: Return true if the port is available, false otherwise.

Parameters:

  • port, port to be checked

Example:

if (JutilasNet.getInstance().isAvailablePort(8080)) {
  // your code
}