Bottom line: instance fields can't be used from static methods (which is what main is). An easy solution for this pair of classes would be to make the fields static. While that would be OK to make this example work, it would be the wrong solution once you integrate the code into the overall codebase. But the problem wouldn't manifest there, because you wouldn't have static methods.
Seeing as you have put a lot of effort into this, I'll make an exception to our rule and post the full code of client and server that use no static fields. There's a static main method, but that's just for testing.
In the server code, the important lines are 9 and 10, which you need to incorporate into your larger code. On the client side, it's lines 16 and 17.
The code completely punts on error handling, which obviously your code can't do once you put it into use.
The other issue is that the server waits until "exit" is sent before returning. So you can't call it from the main thread of your larger app, as it would block it. It needs to be called from a background thread.
Many thanks to Tim and Ron (esp. for your patience)
I was mistakenly sending a null message - hence the error
I now have everything working
Sockets and thread are all new territory for me
A final question:
Suppose I add another two clients to the mix
The server starts its background thread very early on in the main java program
The clients start their background threads after a lot of calculations
Thus the server is listening before the clients are sending their messages
Is there a simple way to code such that the server waits until it has received all 3 messages from the three clients (one message each)
before it continues to make its FINAL overall trading decision based on all 4 individual trading decisions (3 clients and itself) ?
Hopefully, without involving any new concepts such as schedulers