简体   繁体   English

套接字同步 - Java客户端到MATLAB服务器

[英]Socket Synchronization - Java Client to MATLAB Server

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. 我有一个我正在实现的系统,我有一个使用套接字接受TCP连接的MATLAB服务器,以及一个连接到该服务器的Java客户端。

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... 我的问题是,当服务器接受客户端的连接时,显然,客户端设法在服务器设法到达一行代码之前发送输入,该代码行将其锁定为从客户端读取预期的输入...

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? 假设我不知道等待多长时间是安全的,在一般情况下,有没有办法解决所有情况下的这个问题?

Could I use some sort of lock object, shared between MATLAB and Java? 我可以使用MATLAB和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? 如果是这样,我怎么能保证服务器在向客户端发送这样的通知后会急于收听,速度够快?

Thanks in advance! 提前致谢!

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. 顺便说一下,如果有人知道在MATLAB中从Java(System.currentTimeMilis())获取系统时间的简单方法,那么进一步测试它会很有用。 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. 我知道在MATLAB中有很多函数可以访问时间,但我真的不知道是否有任何(或任何方式)可以像Java一样完全相同。

There are easier ways to call Matlab from Java - JMI for example: http://undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/ 有更简单的方法从Java调用Matlab - 例如JMI: http//undocumentedmatlab.com/blog/jmi-java-to-matlab-interface/

Regarding the system time, run this in Matlab: 关于系统时间,在Matlab中运行:

javaTime = java.lang.System.currentTimeMillis javaTime = java.lang.System.currentTimeMillis

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM