title: Java client/server application with sockets?
body: <p>I'm writing a java package that will be called by another language (matlab).  If my matlab process ends, I want the Java process to keep running.  Whenever matlab starts again, it should be able to communicate with the existing running process.  So I think I need to have the Java application communicating through sockets in a client/server model.  I envision having a simple set of functions:</p>
  
  <ul>
  <li>startServer(host, port)</li>
  <li>runCommand(server, command...)</li>
  <li>stopServer(host, port)</li>
  </ul>
  
  <p>I have never done anything like this before.  Am I thinking about it in the right way, or is there an easier way of building an application that can run independently of it's parent's process?  What's the best modern way of doing this (e.g. are there any good Apache packages)?  Can anyone provide a simple demo or point me to a tutorial on communicating with a process through sockets?</p>
  
  <p><em>[Edit]</em> For some clarification, matlab is able to instantiate a java object and run java code within itself.  So the startServer() function in matlab would run java code that will check if a java process is already running on that port and if not, start the server process.  </p>
  
  <p>I'm not tied to using sockets by any means (in case it isn't obvious, I'm mostly a matlab developer), so if there's something easier, I'm all for it.  I just need to be able to run things independently of matlab, but have matlab control those processes (through java).  </p>