title: Socket Synchronization - Java Client to MATLAB Server
body: <p>I have a system I am implementing where I have a MATLAB Server who uses a socket to accept a TCP connection, and a Java Client which connects to that server.</p>
  
  <p>My problem is that when the server accepts the client's connection, apparently, the client manages to send the input before the server manages to reach a line of code that locks it into reading the expected input from the client...</p>
  
  <p>Assuming I do not know how much time to wait would be safe, in a generic case, is there any way to solve this problem for all situations? </p>
  
  <p>Could I use some sort of lock object, shared between MATLAB and Java? Should I assume that the client always awaits some sort of confirmation from the server? and if so, how exactly can i have a guarantee that the server will rush to listen after sending such a notification to the client, fast enough?</p>
  
  <p>Thanks in advance!</p>
  
  <p>By the way, if anyone knows of a simple way of getting the system time from Java (System.currentTimeMilis()) in MATLAB, it would be useful to further test this. I know there are quite some functions to access time in MATLAB, but I don't really know if there is any (or any way) to get it exactly the same way as in Java.</p>