I am using javax.websockets to have a webSocket connection with Blockchain.info, except that it closes down after random intervals, and I can see the close reason as:

'Unexpected end of stream', Error Code = 1006.

I am not able to figure out why this occurs. Here is the code:

private void initializeWebSocketSession(Session session)
    WebSocketContainer container container = ContainerProvider.getWebSocketContainer();
    Session session = container.connectToServer(BlockchainWebSocketClient.class, URI.create("wss://ws.blockchain.info/inv"));               

public void onOpen(Session session) throws IOException

public void onMessage(String message, boolean isLastPartOfMessage)
    // Some logic
  • Quoting RFC 6455: 1006 is [...] designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame. It sounds like your connection to blockchain.info is dropping occasionally. If you use ping -t blockchain.info, are some packets dropped?
    – Nick ODell
    Jan 19 '15 at 7:47
  • Sending a ping message after every 30 seconds to the server endpoint did the trick. But now I get the issue 'Connection reset by peer', same closing code. Thanks for the answer btw.
    – Syed Waqas
    Jan 20 '15 at 13:19
  • @NickODell: Perhaps you could make that comment an answer?
    – Murch
    Jun 20 '17 at 5:25
  • @Murch I don't think it solved his problem. It sounds like he's just getting TCP RST's now.
    – Nick ODell
    Jun 20 '17 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.