java ticker Client connection refused exception

ayyaz
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
... 8 more


getting this exception in java ticker , how can i fix this
  • sujith
    Are you sending a valid api_key and access_token?
    Can you give more details about how and when it happens?
  • ayyaz
    where to catch connection refused exception consider i lost internet connectivity , since you are providing call backs and there is no way for programmer to catch exception , like onconnection doesnt make sense
  • sujith
    You can use onErrorListener to listen to errors.
  • ayyaz
    please point to an example
  • sujith
    You can set it like setting any other listener as mentioned here.
  • ayyaz
    already done , but connection refused is not handled , i dont find any call back for onErrorListener in your link
  • sujith
    Is this crashing the app?
    We will add the callback to the examples. But ideally, all the errors are handled and sent to the user via onErrorListener.
    Can you give complete stack trace, so that we can see where is it thrown from our code?
  • ayyaz

    Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more

    you can see in stack trace connection got disconnected , tcp detected , due to this reconnect was attempted but since there was no net connectivity connection got refused resulted in application crash if u can quickly paste the solution clearly which i can add right away , please dont point anywhere which leads to confusion ...
  • Kailash
    if u can quickly paste the solution clearly which i can add right away , please dont point anywhere which leads to confusion ...
    I'm afraid that's not how it works, @ayyaz. We cannot give you ready-made code that you can copy paste and will magically solve all your problems. There are enough examples on the clients to get you started and we have a comprehensive documentation. You can also look at the source code of the client libraries, which themselves are straight forward.
  • ayyaz
    I am not expecting that my question is straight please provide me solution asap rather than unrelated discussion
    Please let me know how can I catch network exceptions like connection refused or not reachable


    Also recently this exception received please suggest on that too
  • sujith
    You need to listen to errors by implementing the onErrorListener and handle there.
    You can check out updated examples in javakiteconnect repository.
  • ayyaz
    OK how I reconnect if connection refused
    Or if websocket error what is correction method in error listener
  • ayyaz
    Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-111-generic x86_64)

    * Documentation: https://help.ubuntu.com/
    New release '16.04.3 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.

    Last login: Wed Feb 7 13:58:42 2018 from 223.237.221.80
    ali@juststocks:~$ sudo su
    [sudo] password for ali:
    root@juststocks:/home/ali# python genaccesscode.py --userid YH2215 --reqkey flu724txdbu2kvdylnr4hz0e6l75scod ^C
    root@juststocks:/home/ali# tail -f /var/log/juststocks/zerodha_pricer/price_07-02-18
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    ^C
    root@juststocks:/home/ali# tail -20 /var/log/juststocks/zerodha_pricer/price_07-02-18
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    com.neovisionaries.ws.client.WebSocketException: Failed to connect to 'ws.kite.trade:443': ws.kite.trade
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:136)
    at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    root@juststocks:/home/ali# tail -30 /var/log/juststocks/zerodha_pricer/price_07-02-18
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    com.neovisionaries.ws.client.WebSocketException: Failed to connect to 'ws.kite.trade:443': ws.kite.trade
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:136)
    at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    root@juststocks:/home/ali#
  • ayyaz
    Welcome to Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-111-generic x86_64)

    * Documentation: https://help.ubuntu.com/
    New release '16.04.3 LTS' available.
    Run 'do-release-upgrade' to upgrade to it.

    Last login: Wed Feb 7 13:58:42 2018 from 223.237.221.80
    ali@juststocks:~$ sudo su
    [sudo] password for ali:
    root@juststocks:/home/ali# python genaccesscode.py --userid YH2215 --reqkey flu724txdbu2kvdylnr4hz0e6l75scod ^C
    root@juststocks:/home/ali# tail -f /var/log/juststocks/zerodha_pricer/price_07-02-18
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    ^C
    root@juststocks:/home/ali# tail -20 /var/log/juststocks/zerodha_pricer/price_07-02-18
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    com.neovisionaries.ws.client.WebSocketException: Failed to connect to 'ws.kite.trade:443': ws.kite.trade
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:136)
    at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    root@juststocks:/home/ali# tail -30 /var/log/juststocks/zerodha_pricer/price_07-02-18
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    com.neovisionaries.ws.client.WebSocketException: Failed to connect to 'ws.kite.trade:443': ws.kite.trade
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:136)
    at com.neovisionaries.ws.client.SocketConnector.connect(SocketConnector.java:83)
    at com.neovisionaries.ws.client.WebSocket.connect(WebSocket.java:2152)
    at com.zerodhatech.ticker.KiteTicker.connect(KiteTicker.java:202)
    at com.zerodhatech.ticker.KiteTicker.reconnect(KiteTicker.java:631)
    at com.zerodhatech.ticker.KiteTicker.access$200(KiteTicker.java:30)
    at com.zerodhatech.ticker.KiteTicker$2.run(KiteTicker.java:130)
    at java.util.TimerThread.mainLoop(Timer.java:555)
    at java.util.TimerThread.run(Timer.java:505)
    Caused by: java.net.UnknownHostException: ws.kite.trade
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:589)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:673)
    at com.neovisionaries.ws.client.SocketConnector.doConnect(SocketConnector.java:120)
    ... 8 more
    root@juststocks:/home/ali#
Sign In or Register to comment.