Sending Data from Java Application to MT4 EA

 

I want to send data (values of 5 string-variables) from my Java application to my MT4 EA.

I have tried this by making the Java application write to a txt-file and copying the file to MT4-data-folder and an EA accessing the txt-file using FILE_SHARED_READ, however this was not working.

Does anybody know a better way to send data/text from a Java application to an MT4 EA? Thanks in advance!

 
Why did it not work ?
 

The Java application is refreshing the txt-file about 10-20 times per second and copying it to MT4-data-folder. If the MT4 EA is not running, this process is working absolutely fine.

However when the MT4 EA starts reading the txt-file (using FILE_SHARED_READ), it seems the txt-file cannot be modified/refreshed any more by the Java application.

 
jan100:

The Java application is refreshing the txt-file about 10-20 times per second and copying it to MT4-data-folder. If the MT4 EA is not running, this process is working absolutely fine.

However when the MT4 EA starts reading the txt-file (using FILE_SHARED_READ), it seems the txt-file cannot be modified/refreshed any more by the Java application.

Maybe you can use a shared token so that only one out of both can handle the file at a time.

like check read done check write done etc. to sync them in a bidirectional fashion.

Or you can use already present unidirectional communication like pipes.

Please see CNamedPipes class CNamedPipes.mqh

Or https://www.mql5.com/en/articles/115

A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes
A DLL-free solution to communicate between MetaTrader 5 terminals using Named Pipes
  • 2010.07.01
  • investeo
  • www.mql5.com
The article describes how to implement Interprocess Communication between MetaTrader 5 client terminals using named pipes. For the use of the named pipes, the CNamedPipes class is developed. For the test of its use and to measure the connection throughput, the tick indicator, the server and client scripts are presented. The use of named pipes is sufficient for real-time quotes.
 
jan100:

The Java application is refreshing the txt-file about 10-20 times per second and copying it to MT4-data-folder. If the MT4 EA is not running, this process is working absolutely fine.

However when the MT4 EA starts reading the txt-file (using FILE_SHARED_READ), it seems the txt-file cannot be modified/refreshed any more by the Java application.

Just to check - you are using both FILE_READ and FILE_SHARE_READ flags? You need both
 

Thanks for the replies. I will take a look at the named pipes solution.

@honest_knave: Of course using both. Without FILE_READ it is not working at all.

 
Another question is how the file is created and updated in Java.
Reason: