0

I have a windows service which opens a TCP port (one that was available at given moment). Now I need to connect a client to that port. How do I let the client know which port the server is running on?

ed22
  • 1,127
  • 2
  • 14
  • 30

2 Answers2

0

Unless you have some way to communicate with the service from your Java program, this will not be that simple. One solution could be to try parsing the output of the netstat command. For more details on how to do that you can look at this question

user464014
  • 140
  • 8
0

You can't really solve this in the general case without either having the client try all the ports until it somehow recognizes the server, or communicating by some other method.

The easiest solution is to agree on a file name in an agreed location (the temp directory, for example) and store the port number in that file.

  • Thanks, I was thinking about a file to but was hoping to get some neater ideas here haha – ed22 Jun 29 '18 at 14:51