<p>I was using bitcoin's port. Should have provided a port for litecoin: <code>9332</code>.</p>

CC BY-SA 3.0
2017-12-19T09:25:22.423Z
2017-12-19T09:25:22.423Z
Salvador Dali
<p>Playing around with litecoin json-rpc running on windows (the API is the same as bitcoin, so I am using <a href="https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list" rel="nofollow noreferrer">bitcoin's</a> references).</p>

<p>My <code>litecoin.conf</code> has the following data:</p>

<pre><code>rpcuser=user
rpcpassword=pass
txindex=1
</code></pre>

<p>Based on the <a href="https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#JSON-RPC" rel="nofollow noreferrer">documentation</a> I started the core client as <code>.\litecoind.exe -server</code>, and it looks like it works just fine because I can run various commands from another window (<code>.\litecoin-cli.exe getblockcount</code> and many other work as expected).</p>

<p>Now I wanted to make some json-rpc calls and I tried <a href="https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Go" rel="nofollow noreferrer">Go's library</a> which bitcoin's developers recommend. I used the <a href="https://github.com/btcsuite/btcd/blob/master/rpcclient/examples/bitcoincorehttp/main.go" rel="nofollow noreferrer">example from that library's github</a> and the only modifications which I introduced were my <code>user</code> and <code>pass</code> in the definition of the <code>ConnConfig</code>.</p>

<p>The code fails during the execution of <a href="https://github.com/btcsuite/btcd/blob/master/rpcclient/examples/bitcoincorehttp/main.go#L33" rel="nofollow noreferrer">client.GetBlockCount()</a> with an error: </p>

<blockquote>
  <p>Post <a href="http://localhost:8332" rel="nofollow noreferrer">http://localhost:8332</a>: dial tcp [::1]:8332: connectex: No
  connection could be made because the target machine actively refused
  it.</p>
</blockquote>

<p>I think that the problem is with json-rpc server but I have no idea how to verify that it works properly. Any idea how to fix it?</p>

CC BY-SA 3.0
2017-12-18T07:05:09.140Z
So the machine you are trying to connect to refuses tcp or http over tcp ports. Note it does say http not https, Google browser refuses http connections as well as related software api's I assume as well. Http is generally considered outdated as it is completely insecure/no encryption.
marshal craft
CC BY-SA 3.0
2017-12-18T09:44:10.763Z
@marshalcraft when I changed it to https, the result was the same: `Post https://localhost:8332: dial tcp [::1]:8332: connectex: No connection could be made because the target machine actively refused it.`
Salvador Dali
CC BY-SA 3.0
2017-12-18T11:19:46.073Z
Well I don't know best strategy to trouble shoot, but I would try to establish an tcp https connection to rule out that the server simply closed on the relevant port. From the error it says you do not even have a connection. Sometimes errors can give misleading causes. This is deterministic approach but if you have more experience, maybe it's another issue.
marshal craft
CC BY-SA 3.0
2017-12-18T11:20:49.920Z
Also barring that it isn't an http refusal I would go back to http then if you aren't concerned about security, slightly better performance.
marshal craft
CC BY-SA 3.0
2017-12-18T11:24:20.030Z
Like if your any good with Berkeley sockets or winsock do a http get request on the http port and you should get an redirect or even a refusal and then close but you don't get a winsock error code for failure to tcp connect you know then it's http JavaScript API configuration issue and not that there isn't a server.
marshal craft
CC BY-SA 3.0
2017-12-18T18:05:36.140Z
@marshalcraft thank you for helping me to debug my problem. Now I believe that I am providing a wrong port: 8332 is a bitcoin port. Will try [9332](https://github.com/litecoin-project/litecoin/search?utf8=%E2%9C%93&q=9332&type=) or will provide my own in a [config](https://gist.github.com/dasher/4360286). Will check later whether any of this helps
Salvador Dali
CC BY-SA 3.0
2017-12-22T07:21:31.903Z
Nice wish I could have been more helpful, but at least I guess it was dropping the tcp connection at the get go? Not sure how it was seeing litecoin stuff, unless it was a litecoin only server and you were using port for btc server.
marshal craft
<json-rpc>
Json-rpc fails with "No connection could be made because the target machine actively refused it"
Salvador Dali
# Json-rpc fails with "No connection could be made because the target machine actively refused it"

(Asked by: username_0 on 2017-12-18)

Playing around with litecoin json-rpc running on windows (the API is the same as bitcoin, so I am using [bitcoin's](https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list) references).

My `litecoin.conf` has the following data:

```
rpcuser=user
rpcpassword=pass
txindex=1

```

Based on the [documentation](https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#JSON-RPC) I started the core client as `.\litecoind.exe -server`, and it looks like it works just fine because I can run various commands from another window (`.\litecoin-cli.exe getblockcount` and many other work as expected).

Now I wanted to make some json-rpc calls and I tried [Go's library](https://en.bitcoin.it/wiki/API_reference_(JSON-RPC)#Go) which bitcoin's developers recommend. I used the [example from that library's github](https://github.com/btcsuite/btcd/blob/master/rpcclient/examples/bitcoincorehttp/main.go) and the only modifications which I introduced were my `user` and `pass` in the definition of the `ConnConfig`.

The code fails during the execution of [client.GetBlockCount()](https://github.com/btcsuite/btcd/blob/master/rpcclient/examples/bitcoincorehttp/main.go#L33) with an error:

> Post <http://localhost:8332>: dial tcp [::1]:8332: connectex: No
> connection could be made because the target machine actively refused
> it.

I think that the problem is with json-rpc server but I have no idea how to verify that it works properly. Any idea how to fix it?

**Tags:** json-rpc

> **Comments:**
> **username_1**: So the machine you are trying to connect to refuses tcp or http over tcp ports. Note it does say http not https, Google browser refuses http connections as well as related software api's I assume as well. Http is generally considered outdated as it is completely insecure/no encryption.  
> **username_0**: @username_1 when I changed it to https, the result was the same: `Post https://localhost:8332: dial tcp [::1]:8332: connectex: No connection could be made because the target machine actively refused it.`  
> **username_1**: Well I don't know best strategy to trouble shoot, but I would try to establish an tcp https connection to rule out that the server simply closed on the relevant port. From the error it says you do not even have a connection. Sometimes errors can give misleading causes. This is deterministic approach but if you have more experience, maybe it's another issue.  
> **username_1**: Also barring that it isn't an http refusal I would go back to http then if you aren't concerned about security, slightly better performance.  
> **username_1**: Like if your any good with Berkeley sockets or winsock do a http get request on the http port and you should get an redirect or even a refusal and then close but you don't get a winsock error code for failure to tcp connect you know then it's http JavaScript API configuration issue and not that there isn't a server.  
> **username_0**: @username_1 thank you for helping me to debug my problem. Now I believe that I am providing a wrong port: 8332 is a bitcoin port. Will try [9332](https://github.com/litecoin-project/litecoin/search?utf8=%E2%9C%93&q=9332&type=) or will provide my own in a [config](https://gist.github.com/dasher/4360286). Will check later whether any of this helps  
> **username_1**: Nice wish I could have been more helpful, but at least I guess it was dropping the tcp connection at the get go? Not sure how it was seeing litecoin stuff, unless it was a litecoin only server and you were using port for btc server.  

---

## 1 answers

### Answer by username_0 on 2017-12-19. Score: 2 | Accepted answer

I was using bitcoin's port. Should have provided a port for litecoin: `9332`.


---

