connect() and isConnected() problems

305 views
Skip to first unread message

Antony

unread,
Mar 16, 2014, 2:36:05 AM3/16/14
to nj...@googlegroups.com
Hi, 
i'm trying to handle the connection of my application automatically.
So, i created a thread that checks each 10seconds if strategy class is connected, and if it's connected show me OK, else try to connect again.
I use this method in my class, where stg is Strategy attribute:

public boolean isConnected(){
boolean isConnected=false;
try{
isConnected=stg.isConnected();
}catch(Exception e){
isConnected=false;
}
return isConnected;
}

So, in thread, if(!isConnected()), the strategy is connected, else show me "OK".

I tryed to do some tests:
1) i tryed to close terminal using close_all_nj4x_terminals.bat:
Using stg.setRreconnect(true),i have this behaviour: for about 4/5 minutes,i have "java.lang.RuntimeException: 2088800058 is already connecting to Armada-DemoUK" and (using SW_HIDE false) i can see terminal went open and closed continuosly. After this time, i can see stg.connect() hang for some seconds, and at the end all came back ok and isConnected() answered true.

Using stg.setRreconnect(false), i have this behaviour: 
the connect() hang up for about 20-30second, and after give me this:
java.lang.NullPointerException
at com.jfx.strategy.Strategy.startCoordination(Strategy.java:947)
at com.jfx.strategy.Strategy.connect(Strategy.java:926)
at com.jfx.strategy.Strategy.connect(Strategy.java:603)
After this exception, isConnected() is true!


2) i tryed to stop internet connection for some time. At restart internet connecion i had this behaviour:
Using stg.setRreconnect(true), at some point stg.connect() hang up one time for more than 5 minutes... than i stopped my application because i have no more answer from connect() method!
Using stg.setRreconnect(false), stg.connect() hang up about 5/6 times, for about 2 minutes each one, i can see terminal went opened and closed, but nothing happened and i stop my application.

So in both point 2's cases, never more isConnected() return me true!



Please, can you clarify how we can do the correct check? 
More, when internet connection went down, seems the strategy doesn't want connect anymore...


Thank you,

      Antonio

Roman Gerasimenko

unread,
Mar 17, 2014, 9:26:43 AM3/17/14
to nj...@googlegroups.com
Hi Antonio,

In case you need to check connection between your app and MT4 terminal, please use IsConnectedToTerminal() Strategy method.

Do you use UDP connection mode ?

--
You received this message because you are subscribed to the Google Groups "NJ4X Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nj4x+uns...@googlegroups.com.
To post to this group, send email to nj...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anton Nikulin

unread,
Mar 17, 2014, 12:36:23 PM3/17/14
to nj...@googlegroups.com
Hi Roman

What is the difference between isConnectedToTerminal() and isConnected() methods? 

Thanks, Anton

Antony

unread,
Mar 17, 2014, 3:28:59 PM3/17/14
to nj...@googlegroups.com
Hi, 
i don't use UDP because with some tests done time ago it was very unstable, maybe you remember my precedent topic.

About  IsConnectedToTerminal() and IsConnected(), can you explain exact differences between them?

IsConnectedToTerminal() returns if strategy object is connected to jfx EA? and if we have more charts (e.g. ticklistener or positionlistener charts), it returns the state of which connection?
IsConnected() return status of which connection? In my tests I noted that if i stop my internet connection it return false...


Can you explain us, please?

Thanks

Antony

unread,
Mar 17, 2014, 4:27:49 PM3/17/14
to nj...@googlegroups.com
I'm doing other tests.
What i can't be able to handle is the HANG UP of Strategy Object on connect() method, when a new connection is needed beacuse i manual close terminal.
It hangs up, coordinate code doesn't run anymore, and i cannot do anything!
I wait, wait wait.... but nothing happens. I have to close and reopen my application forcing killing of terminal.exe at exit: s.close(true).

Can you please use a timeout or something other, so that connect() does not HANG UP overall our applications?

Thanks

Roman Gerasimenko

unread,
Mar 18, 2014, 4:58:01 AM3/18/14
to nj...@googlegroups.com
On Mon, Mar 17, 2014 at 6:36 PM, Anton Nikulin <anton...@gmail.com> wrote:
Hi Roman

What is the difference between isConnectedToTerminal() and isConnected() methods? 


isConnectedToTerminal() verifies connection between JFX EA (mt4 terminal) and the application.

isConnected() method is NJ4X API reflection of MQL4 IsConnected (http://docs.mql4.com/check/isconnected) and checks connection between client terminal and server.

Roman Gerasimenko

unread,
Mar 18, 2014, 5:02:20 AM3/18/14
to nj...@googlegroups.com
On Mon, Mar 17, 2014 at 9:28 PM, Antony <antob...@gmail.com> wrote:
Hi, 
i don't use UDP because with some tests done time ago it was very unstable, maybe you remember my precedent topic.

About  IsConnectedToTerminal() and IsConnected(), can you explain exact differences between them?

IsConnectedToTerminal() returns if strategy object is connected to jfx EA? and if we have more charts (e.g. ticklistener or positionlistener charts), it returns the state of which connection?

Correct. 
It returns a state of the connectiuon it was called on (TickListeners also have mt4 connection parameter (public void onTick(TickInfo tick, MT4 connection) 
 
IsConnected() return status of which connection? In my tests I noted that if i stop my internet connection it return false...


isConnected() method is NJ4X API reflection of MQL4 IsConnected (http://docs.mql4.com/check/isconnected) and checks connection between client terminal and server.
 

Roman Gerasimenko

unread,
Mar 18, 2014, 5:09:22 AM3/18/14
to nj...@googlegroups.com
On Mon, Mar 17, 2014 at 10:27 PM, Antony <antob...@gmail.com> wrote:
I'm doing other tests.
What i can't be able to handle is the HANG UP of Strategy Object on connect() method, when a new connection is needed beacuse i manual close terminal.

Please explain your scenario. As you aware there are two modes NJ4X api applies to

1st - App driven - you need to start TS and use connect method from the application. In this scenario you sould not try to kill/manage terminals as long as it is TS' job. 

2nd - You manually start mt4 terminal, drop jfx.ex4 EA to it and it connects to the application - in this case no connect method should be called.

 
It hangs up, coordinate code doesn't run anymore, and i cannot do anything!
I wait, wait wait.... but nothing happens. I have to close and reopen my application forcing killing of terminal.exe at exit: s.close(true).

Can you please use a timeout or something other, so that connect() does not HANG UP overall our applications?


Please collect nj4x logs with this utility - https://www.dropbox.com/s/prj8e1z16kjpv1w/NJ4X_LOG_UTILS.7z
Send me them privately and specify time period of the HANG problem I need to check.

Antony

unread,
Mar 18, 2014, 12:01:50 PM3/18/14
to nj...@googlegroups.com
My application is app driven, using terminal server.
I do this:
- my application starts, it checks for isConnectedToTerminal() and if false run connect() on strategy
- in first connect() all is ok!
- to see if my app answers ok to connections problem, i simulate jfx EA connection's drop by killing terminal, using "close_all_nj4x_terminals.bat".
- my app, that checks for isConnectedToTerminal() each 5 seconds, get "false" on it and run connect() again.

It's this second connect() that hangs up, without no more answer.

But, the weird thing, is that it not happens always. Sometime it reconnects ok, and other times it hangs up.

Anyway, I try to generate some useful logs for you.

Thanks

     Antonio

Antony

unread,
Mar 21, 2014, 6:21:57 AM3/21/14
to nj...@googlegroups.com
Ok, it seems that if i not run connect() when connection to temrinal is established, all it's running ok.
Problems happen when i run connect() and there is already the connection established. So, i can prevent this useing isConnectedToTerminal() method.

I have an other question at this time. What does this method?

setReconnect(boolean reconnect) 


Thanks,

    Antonio

Roman Gerasimenko

unread,
Mar 24, 2014, 3:58:18 PM3/24/14
to nj...@googlegroups.com
setReconnect(true) makes your Strategy instance automatically reconnect to the mt4 terminal in case of network connection between your app and mt4 terminal is lost. You can call setReconnect() method anytime - it simply modifies internal flag field, which is used only in case of connection problems.
Reply all
Reply to author
Forward
0 new messages