# httpClient() question

**URL:** <https://forum.inductiveautomation.com/t/httpclient-question/94084>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [August 1, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/httpclient-question/94084 "2024-08-01T19:37:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Travis\_Graham](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travis_graham/32/53480_2.png) [@Travis\_Graham](https://forum.inductiveautomation.com/u/Travis_Graham)\
**Post date:** [August 1, 2024, 7:37pm UTC](https://forum.inductiveautomation.com/t/httpclient-question/94084/1 "2024-08-01T19:37:00Z")

</div>

I'm working on communicating data to a Diagraph IJ4000 packaging line printer. Right now I've settled on using system.net.httpClient() to send the data. The scripting is very basic, as the printer has built-in cgi scripts where all I'm doing is sending a GET and the URL that includes the target cgi and any data parameters.

My Project script looks as such:

```python
# Create the JythonHttpClient.
client = system.net.httpClient()

def loadDiagraph(ipAddress,printTemplate,lotNumber,mfgDate,expireDate):
		#Send Data & Start Print requst 
		client.get("http://"+ipAddress+"/serial.cgi?idx=0&nme="+printTemplate+"&fst=1&lst=3&d1="+lotNumber+"&d2="+mfgDate+"&d3="+expireDate+"&net=1")

```

I'm then calling the script from inside a "Load Printer" button I've placed on a screen.  
This works without fault, but I've read through multiple forum threads about being careful with calling the system.net.httpClient() too much or in specific scenarios - most of which is beyond my current knowledge and I'm not understanding.

Right now we're testing a single printer, but I could end up with as many as 6-7 line printers which I'll need to send data to in this manner.

Is there a way to see if I've opened too many connections? Do I need to close the connection(s) somehow after sending the data? If so, how?

Thank you for any assistance!

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 1, 2024, 7:40pm UTC](https://forum.inductiveautomation.com/t/httpclient-question/94084/2 "2024-08-01T19:40:19Z")

</div>

You're fine. You created the `client` variable outside any function definition, making it shared across all callers. Which is precisely what you should do.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 1, 2024, 7:47pm UTC](https://forum.inductiveautomation.com/t/httpclient-question/94084/3 "2024-08-01T19:47:34Z")

</div>

> [@Travis\_Graham](#):
>
> calling the system.net.httpClient() too much or in specific scenario

The concern is more something like "creating an instance of `httpClient` every single time a particular button is pressed in a Perspective project" - which means you're creating an instance per session multiplied by the number of times end users click the button - very quickly getting out of control and potentially exhausting system memory and other OS level limitations as those clients hold on to additional memory and thread pools.

It's such a concern that in 8.3 there's going to be a 'default' HTTP client instance mounted as `system.net.httpClient` - you'll still be able to construct your own, but for simple cases that don't need customization like your example above, you'll be able to just use `system.net.httpClient.get(url)`.

---

<div class="post-metadata">

**Author:** ![Travis\_Graham](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/travis_graham/32/53480_2.png) [@Travis\_Graham](https://forum.inductiveautomation.com/u/Travis_Graham)\
**Post date:** [August 1, 2024, 10:30pm UTC](https://forum.inductiveautomation.com/t/httpclient-question/94084/4 "2024-08-01T22:30:20Z")

</div>

Thanks for the insight!
