# How to handle external websockets?

**URL:** <https://discourse.nameko.io/t/how-to-handle-external-websockets/352>\
**Category:** Uncategorized\
**Created:** [October 1, 2018, 8:26pm UTC](https://discourse.nameko.io/t/how-to-handle-external-websockets/352 "2018-10-01T20:26:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![No\_Split\_Sherlock](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@No\_Split\_Sherlock](https://discourse.nameko.io/u/No_Split_Sherlock)\
**Post date:** [October 1, 2018, 8:26pm UTC](https://discourse.nameko.io/t/how-to-handle-external-websockets/352/1 "2018-10-01T20:26:44Z")

</div>

Hey there! I’m quite new to microservices and Nameko. I hope someone can help me.  
I’m trying to open multiple websocket clients that receive external datastreams. I want to be able to (at some point) maybe interact with a websocket (close it, change the subscription, send a message). But because the service that started the socket client doesn’t store a reference to the websocket object, I can’t do anything with it.

So my question is, how do I interact with that websocket if the services don’t know where it is? Should I store it somewhere? Make some kind of queue?

---

<div class="post-metadata">

**Author:** ![mattbennett](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/mattbennett/32/13_2.png) [@mattbennett](https://discourse.nameko.io/u/mattbennett)\
**Post date:** [October 2, 2018, 9:47am UTC](https://discourse.nameko.io/t/how-to-handle-external-websockets/352/2 "2018-10-02T09:47:36Z")

</div>

Can you post some example code? I’m not sure what you’re trying to achieve.

When you say websocket _client_, what do you mean exactly?

---

<div class="post-metadata">

**Author:** ![No\_Split\_Sherlock](https://avatars.discourse-cdn.com/v4/letter/n/f17d59/32.png) [@No\_Split\_Sherlock](https://discourse.nameko.io/u/No_Split_Sherlock)\
**Post date:** [October 5, 2018, 10:52am UTC](https://discourse.nameko.io/t/how-to-handle-external-websockets/352/3 "2018-10-05T10:52:24Z")

</div>

I’m sorry I wasn’t clear. I’ve learned since this post that I should write a DependencyProvider to keep states between workers. With websocket client I meant a websocket that primarily receives data as a listener.

I can’t really find anything in de docs on how DependencyProviders keep their state compared to the service itself. From my earlier experimentation I had the impression dependencies keep getting instantiated with every service call but maybe the provider itself behaves differently.

---

<div class="post-metadata">

**Author:** ![spyrosmarko](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.nameko.io/spyrosmarko/32/29_2.png) [@spyrosmarko](https://discourse.nameko.io/u/spyrosmarko)\
**Post date:** [June 10, 2024, 1:06pm UTC](https://discourse.nameko.io/t/how-to-handle-external-websockets/352/4 "2024-06-10T13:06:01Z")

</div>

hi @No_Split_Sherlock,

I know it’s rather old topic, but out of curiosity have you finally setup a websocket client as dependency provider?
