Here is a simple tutorial on how to do that.

A Simple Java TCP Server and TCP Client | systemBash

And I think that is what you looking for, and one another thing, you must always start server...