Hi Richard:
Havent checked in for a while.... see that IB screwed our?
TWS wrapper with this latest version. grrr.
Send me an email (skearns23@...) and tell me about this github project,
maybe I'll contribute.
I use the signal in this capacity, during logon (some lines deleted):
boolean doConnect(int maxtries)
{
{
myLog("In doConnect(" + maxtries + ")");
if (amConnected())
{
myLog("Already connected, so leaving.");
return true;
}
mWantsToBeConnected = true;
myLog("initing logprogress...");
// get connection parameters
String host = ...
int port = ...
int id = 0;
int count = 0;
// connect to TWS
while (!amConnected() && count < maxtries)
{
clearMsgs();
mConnection.eConnect(host, port, id);
// wait for upto 5 seconds for a response
double start = TimeStuff.now();
String response = NO_MSG;
String lastMsg = response;
while (!amConnected() && TimeStuff.now() - start <= 5000)
{
pause(200);
}
lastMsg = this.getLastMsg();
if (!amConnected())
{
myLog("Connection attempt:" + count + " failed with response:\"" + lastMsg + "\"");
pause(1000);
}
count++;
}
if (amConnected())
{
final EReaderSignal signal = new EJavaSignal();
final EReader reader = new EReader(mConnection, signal);
reader.start();
new Thread()
{
@Override
public void run()
{
myLog("The api reader thread is starting.");
while (mConnection.isConnected())
{
signal.waitForSignal();
try
{
reader.processMsgs();
}
catch (IOException e)
{
error(e);
}
}
myLogErr("The api reader thread is quitting.");
}
}.start();
pause(5000);
}
else
{
myLogErr("Connection to TWS failed.");
}
return amConnected();
}
}
@Override
public void connectAck()
{
myLog("Connected IB" + this.mIbIniSuffix + " !!!!");
myConnected = true;
}
public boolean amConnected()
{
return this.mConnection.isConnected() && myConnected;
}