2

I have a message sending program from server to client which is working inside adempiere. Here I have to give supply port: 8080 dynamically, ie. port must not be hardcoded. Now I am hard coding port 8080 at serversocket and socket

Server

    ServerSocket srvr = new ServerSocket(8080, 1, InetAddress.getByName(mSession.getRemote_Addr()));

Client

    Socket skt = new Socket(ip.getHostAddress(), 8080);

Please suggest a method rebel to this hard coding. Please help me.

Antony Joslin
  • 309
  • 4
  • 17

1 Answers1

2

The web port is part of the configuration data that is used when the setup process is run but it isn't accessed by the server/client once the setup is complete. To access the data, you will need to load the configuration data again like this:

int webPort = 8080;
ConfigurationData data = new ConfigurationData(null);
if (data.load()) {
    webPort = data.getAppsServerWebPort ();
}

ServerSocket srvr = new ServerSocket(webPort, 1, InetAddress.getByName(mSession.getRemote_Addr()));
Elzo Valugi
  • 27,240
  • 15
  • 95
  • 114
Michael McKay
  • 650
  • 4
  • 11