/** * @brief Creates socket connection to TWS/IBG. */ public bool EConnect(string host, int port, int clientId, bool extraAuth) { if (IsConnected) { Wrapper.Error(IncomingMessage.NotValid, EClientErrors.AlreadyConnected.Code, EClientErrors.AlreadyConnected.Message); return(true); } try { TcpStream = CreateClientStream(host, port); this.port = port; SocketTransport = new ESocket(TcpStream); ClientId = clientId; ExtraAuth = extraAuth; SendConnectRequest(); if (!AsyncEConnect) { var eReader = new EReader(this, eReaderSignal); while (ServerVersion == 0 && eReader.PutMessageToQueue()) { eReaderSignal.WaitForSignal(); eReader.ProcessMsgs(); } } return(true); } catch (ArgumentNullException ane) { Wrapper.Error(ane); } catch (SocketException se) { Wrapper.Error(se); } catch (EClientException e) { var cmp = e.Err; Wrapper.Error(-1, cmp.Code, cmp.Message); } catch (Exception e) { Wrapper.Error(e); } return(false); }