示例#1
0
        /**
         * @brief Creates socket connection to TWS/IBG.
         */
        public void eConnect(string host, int port, int clientId, bool extraAuth)
        {
            if (isConnected)
            {
                wrapper.error(IncomingMessage.NotValid, EClientErrors.AlreadyConnected.Code, EClientErrors.AlreadyConnected.Message);
                return;
            }
            try
            {
                tcpStream       = createClientStream(host, port);
                this.port       = port;
                socketTransport = new ESocket(tcpStream);

                this.clientId  = clientId;
                this.extraAuth = extraAuth;

                sendConnectRequest();

                if (!AsyncEConnect)
                {
                    var eReader = new EReader(this, eReaderSignal);

                    while (serverVersion == 0 && eReader.putMessageToQueue())
                    {
                        eReaderSignal.waitForSignal();
                        eReader.processMsgs();
                    }
                }
            }
            catch (ArgumentNullException ane)
            {
                wrapper.error(ane);
            }
            catch (SocketException se)
            {
                wrapper.error(se);
            }
            catch (EClientException e)
            {
                var cmp = (e as EClientException).Err;

                wrapper.error(-1, cmp.Code, cmp.Message);
            }
            catch (Exception e)
            {
                wrapper.error(e);
            }
        }
示例#2
0
        public void eConnect(string host, int port, int clientId, bool extraAuth)
        {
            if (isConnected)
            {
                wrapper.error(IncomingMessage.NotValid, EClientErrors.AlreadyConnected.Code, EClientErrors.AlreadyConnected.Message);
                return;
            }
            try
            {
                tcpStream = createClientStream(host, port);
                this.port = port;
                socketTransport = new ESocket(tcpStream);

                this.clientId = clientId;
                this.extraAuth = extraAuth;

                sendConnectRequest();

                if (!AsyncEConnect)
                {
                    var eReader = new EReader(this, eReaderSignal);

                    while (serverVersion == 0 && eReader.putMessageToQueue())
                    {
                        eReaderSignal.waitForSignal();
                        eReader.processMsgs();
                    }
                }
            }
            catch (ArgumentNullException ane)
            {
                wrapper.error(ane);
            }
            catch (SocketException se)
            {
                wrapper.error(se);
            }
            catch (EClientException e)
            {
                var cmp = (e as EClientException).Err;

                wrapper.error(-1, cmp.Code, cmp.Message);
            }
            catch (Exception e)
            {
                wrapper.error(e);
            }
        }