Socket synchronization - Java client to MATLAB server

I have a system that I am implementing, where I have a MATLAB server that uses a socket to receive a TCP connection and a Java client that connects to this server.

My problem is that when the server accepts the client connection, it seems that the client manages to send input before the server can reach the line of code that blocks it when reading the expected input from the client ...

Assuming I don’t know how long it would be safe to wait, in general, is there a way to solve this problem for all situations?

Can I use some kind of lock object shared between MATLAB and Java? Should I assume that the client always expects confirmation from the server? and if so, how exactly can I get a guarantee that the server will hurry to listen after sending such a notification to the client quickly enough?

Thanks in advance!

By the way, if someone knows a simple way to get system time from Java (System.currentTimeMilis ()) in MATLAB, it would be useful to test this further. I know that there are enough functions to access time in MATLAB, but I really don't know if there is any (or any way) to get it exactly the same as in Java.
+3
source share
1 answer

Matlab Java - JMI, : http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/

, Matlab:

javaTime = java.lang.System.currentTimeMillis

+1

All Articles