# No connection could be made because the target machine actively refused it

**URL:** <https://forum.plexim.com/t/no-connection-could-be-made-because-the-target-machine-actively-refused-it/771>\
**Category:** PLECS\
**Tags:** open\
**Created:** [May 4, 2020, 11:47am UTC](https://forum.plexim.com/t/no-connection-could-be-made-because-the-target-machine-actively-refused-it/771 "2020-05-04T11:47:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hridhya](https://avatars.discourse-cdn.com/v4/letter/h/35a633/32.png) [@Hridhya](https://forum.plexim.com/u/Hridhya)\
**Post date:** [May 4, 2020, 11:47am UTC](https://forum.plexim.com/t/no-connection-could-be-made-because-the-target-machine-actively-refused-it/771/1 "2020-05-04T11:47:56Z")

</div>

I am trying to connect to RT Box via XML RPC from Python. Please find the code below

import xmlrpclib  
import socket  
ip = socket.gethostbyname(‘rtbox-20b0f703a3f4’)  
print (ip)  
server=xmlrpclib.Server(“http://” + ip + “:1080/RPC2”)  
with open(“C:Models/boost\_converter\_codegen/Plant.elf”, “rb”) as f:  
print(“Uploading executable”)  
print (server)  
server.rtbox.start()  
print (server)  
server.rtbox.load(xmlrpclib.Binary(f.read()))  
f.closed  
print(“Starting executable”)  
#print (server)  
server.rtbox.start()  
#print(f"IP Address: {ip\_address}")

For the abovecode I get the error

“No connection could be made because the target machine actively refused it.”

Should I enable any port from the RT Box side to listen from host? Firewall is disabled .

---

<div class="post-metadata">

**Author:** ![Manu\_Parimi](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/manu_parimi/32/6_2.png) [@Manu\_Parimi](https://forum.plexim.com/u/Manu_Parimi)\
**Post date:** [May 12, 2020, 9:04pm UTC](https://forum.plexim.com/t/no-connection-could-be-made-because-the-target-machine-actively-refused-it/771/2 "2020-05-12T21:04:48Z")

</div>

Hi Hridhya,

The main issue I’m seeing with your code is that your TCP port is incorrect. The RT Box listens to XML-RPC connections on TCP port 9998. I made a few small fixes to your code. The following code should work.

import xmlrpclibimport socketip = socket.gethostbyname(‘rtbox-20b0f703a3f4.local.’)print (ip)server=xmlrpclib.Server(“http://” + ip + “:9998/RPC2”)with open(“C:Models/boost\_converter\_codegen/Plant.elf”, “rb”) as f: print(“Uploading executable”) server.rtbox.load(xmlrpclib.Binary(f.read()))f.closedprint(“Starting executable”)server.rtbox.start()print(“Real-time simulation running”)

Also, have you checked out the XML Scripting demo model? If you haven’t yet, I recommend you to do so. It is under Window \> Demo Models \> RT Box Demo Models \> XML-RPC Scripting Interface. This demo model is pretty good at explaining this feature step by step, using a simple example.
