<p>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:</p>

<p>'Unexpected end of stream', Error Code = 1006.</p>

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

<pre><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
{
    session.setMaxIdleTimeout(0);
    session.getBasicRemote().sendText("{\"op\":\"unconfirmed_sub\"}");
}

@OnMessage
public void onMessage(String message, boolean isLastPartOfMessage)
{
    // Some logic
}
</code></pre>

CC BY-SA 3.0
2015-01-19T07:47:46.240Z
Quoting [RFC 6455](http://tools.ietf.org/html/rfc6455#page-46): `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
CC BY-SA 3.0
2015-01-20T13:19:45.567Z
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
CC BY-SA 3.0
2017-06-20T05:25:04.147Z
@NickODell: Perhaps you could make that comment an answer?
Murch
CC BY-SA 3.0
2017-06-20T15:21:26.023Z
@Murch I don't think it solved his problem. It sounds like he's just getting TCP RST's now.
Nick ODell
<blockchain.info><java><websockets>
blockchain.info websocket: Error code = 1006, Unexpected end of stream
Syed Waqas
# blockchain.info websocket: Error code = 1006, Unexpected end of stream

(Asked by: username_0 on 2015-01-19)

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
{
    session.setMaxIdleTimeout(0);
    session.getBasicRemote().sendText("{\"op\":\"unconfirmed_sub\"}");
}

@OnMessage
public void onMessage(String message, boolean isLastPartOfMessage)
{
    // Some logic
}

```

**Tags:** blockchain.info, java, websockets

> **Comments:**
> **username_1**: Quoting [RFC 6455](http://tools.ietf.org/html/rfc6455#page-46): `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?  
> **username_0**: 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.  
> **username_2**: @username_1: Perhaps you could make that comment an answer?  
> **username_1**: @username_2 I don't think it solved his problem. It sounds like he's just getting TCP RST's now.  

---

## 0 answers

