Page 1 of 1

Simultaneous connections

Posted: Monday 04 January 2021 20:17
by meyland
I'm developing a plugin and I need to be able to make about 20-30 simultaneous connections to a website.

I don't know how to make all these connections by using the connection object. Can anyone give me a hint? :D

Re: Simultaneous connections

Posted: Monday 04 January 2021 22:08
by pipiche
meyland wrote: Monday 04 January 2021 20:17 I'm developing a plugin and I need to be able to make about 20-30 simultaneous connections to a website.

I don't know how to make all these connections by using the connection object. Can anyone give me a hint? :D
You should check the plugins/examples/HTTP.py
self.httpConn = Domoticz.Connection(Name=self.sProtocol+" Test", Transport="TCP/IP", Protocol=self.sProtocol, Address=Parameters["Address"], Port=Parameters["Mode1"])
And you do as many as you need.

Now if you don't want to use the Connection API you might go for a multi Thread opening their own connection via urlibrequest or other python3 module like that

Re: Simultaneous connections

Posted: Monday 04 January 2021 23:39
by waltervl
There is a Multi-Thread example https://github.com/domoticz/domoticz/bl ... hreaded.py

See also the Wiki for some remarks about this: https://www.domoticz.com/wiki/Developin ... rk_details:

Re: Simultaneous connections

Posted: Tuesday 05 January 2021 7:21
by meyland
Many thanks, I will look at the examples to night

Re: Simultaneous connections

Posted: Wednesday 06 January 2021 6:54
by meyland
a thought: is it possible to use the asyncio module, ie async and await syntax in a plugin?

Re: Simultaneous connections

Posted: Wednesday 06 January 2021 8:57
by pipiche
yes you can use the async

Re: Simultaneous connections

Posted: Wednesday 06 January 2021 17:42
by meyland
Sounds good. Are there any examples on how to use asyncio?