# I cannot connect to ignition server from C/C++ codes

**URL:** <https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912>\
**Category:** General Discussion\
**Created:** [May 6, 2025, 12:36pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912 "2025-05-06T12:36:45Z")\
**Posts on this page:** 8\
**Page:** 2

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 6, 2025, 4:15pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/21 "2025-05-06T16:15:36Z")

</div>

> [@charlie.ye](#):
>
> I have reached the max posts here and I need to wait another 20 hours before posting a new topic.

I just bumped your user level away from "new user", see if you can post or create a new topic now.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 6, 2025, 5:47pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/22 "2025-05-06T17:47:27Z")

</div>

> [@charlie.ye](#):
>
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/7/27bb155d50ae64f1c20b9dcfa8c882218a9a92fc.png)
> 
> ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/8/28c952603c958772b7dc5913ed7b0f60b2dcd8ab.png)
> 
> I still have the connection problem. Let me check Ignition Server settings.

Use `opc.tcp://127.0.0.1:62541` as your endpoint URL. You were at least communicating with the server in that case. When you use "localhost" it seems you never connect at all. There must be something funny happening on Windows with localhost vs 127.0.0.1.

Alternatively, try setting the "Bind Addresses" setting for the Ignition OPC UA server to `0.0.0.0`. Remember to restart.

---

<div class="post-metadata">

**Author:** ![charlie.ye](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@charlie.ye](https://forum.inductiveautomation.com/u/charlie.ye)\
**Post date:** [May 7, 2025, 6:45pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/23 "2025-05-07T18:45:15Z")

</div>

I get the more info by use of my own debug function:

```python
#include <iostream>
#include <memory>
#include <open62541/client_config_default.h>

void debugLogger(void* context, UA_LogLevel level, UA_LogCategory category, const char* msg, va_list args);

int main()
{
	UA_StatusCode status = UA_STATUSCODE_GOOD;
	std::unique_ptr<UA_Client, decltype(&UA_Client_delete)> client(UA_Client_new(), UA_Client_delete);
	UA_ClientConfig* cfg = UA_Client_getConfig(client.get());
	cfg->logging->log = debugLogger;

	status = UA_ClientConfig_setDefault(cfg);
	if (status != UA_STATUSCODE_GOOD) {
		std::cout << "StatusCode: " << UA_StatusCode_name(status) << "\n";
		return EXIT_FAILURE;
	}
#if 0
	status = UA_Client_connect(client.get(), "opc.tcp://ATL-N0012.DataManag.local:53530/OPCUA/SimulationServer");
#else
	status = UA_Client_connect(client.get(), "opc.tcp://localhost:62541/discovery");
#endif
	if (status != UA_STATUSCODE_GOOD) {
		std::cout << "StatusCode: " << UA_StatusCode_name(status) << "\n";
		return EXIT_FAILURE;
	}
	return status == UA_STATUSCODE_GOOD ? EXIT_SUCCESS : EXIT_FAILURE;
}

void debugLogger(void* context, UA_LogLevel level, UA_LogCategory category, const char* msg, va_list args) {
	const char* levelStr = "";
	switch (level) {
	case UA_LOGLEVEL_TRACE: levelStr = "TRACE"; break;
	case UA_LOGLEVEL_DEBUG: levelStr = "DEBUG"; break;
	case UA_LOGLEVEL_INFO: levelStr = "INFO"; break;
	case UA_LOGLEVEL_WARNING: levelStr = "WARNING"; break;
	case UA_LOGLEVEL_ERROR: levelStr = "ERROR"; break;
	case UA_LOGLEVEL_FATAL: levelStr = "FATAL"; break;
	}

	const char* catStr = "";
	switch (category) {
	case UA_LOGCATEGORY_NETWORK:
		catStr = "NETWORK";
		break;
	case UA_LOGCATEGORY_SECURECHANNEL:
		catStr = "SECURECHANNEL";
		break;
	case UA_LOGCATEGORY_SESSION:
		catStr = "SESSION";
		break;
	case UA_LOGCATEGORY_SERVER:
		catStr = "SERVER";
		break;
	case UA_LOGCATEGORY_CLIENT:
		catStr = "CLIENT";
		break;
	case UA_LOGCATEGORY_USERLAND:
		catStr = "USERLAND";
		break;
	case UA_LOGCATEGORY_SECURITYPOLICY:
		catStr = "SECURITYPOLICY";
		break;
	case UA_LOGCATEGORY_EVENTLOOP:
		catStr = "EVENTLOOP";
		break;
	case UA_LOGCATEGORY_PUBSUB:
		catStr = "PUBSUB";
		break;
	case UA_LOGCATEGORY_DISCOVERY:
		catStr = "DISCOVERY";
		break;
	default:
		catStr = "UNKNOWN";
		break;
	}
	printf("[%s][%s] ", levelStr, catStr);
	vprintf(msg, args);
	printf("\n");
}

```

Ignition OPC server windows

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/3/5319bb2bd8e97465ade57c471ab10933a6bdbab9.png)

Prosys:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/f/0f1850de2f275628a1c5fe2e394482262d4ff31b.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [May 7, 2025, 7:04pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/24 "2025-05-07T19:04:07Z")

</div>

> [@Kevin.Herron](#):
>
> It's probably trying to call the CreateSession service against the discovery endpoint at `opc.tcp://localhost:62541/discovery` instead of the session endpoint at `opc.tcp://localhost:62541`.

> [@charlie.ye](#):
>
> ```python
> status = UA_Client_connect(client.get(), "opc.tcp://localhost:62541/discovery");
> 
> ```

🤷

---

<div class="post-metadata">

**Author:** ![charlie.ye](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@charlie.ye](https://forum.inductiveautomation.com/u/charlie.ye)\
**Post date:** [May 7, 2025, 7:08pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/25 "2025-05-07T19:08:53Z")

</div>

Thanks a lot. All apps are running on windows platform. My client test app is compiled with Visual C++ 2022. It works with Prosys OPC UA simulator server, but doesn't with Ignition OPC UA server!

If I use the end point url 'opc.tcp://127.0.0.1:62541/discovery' instead of 'opc.tcp://localhost:62541/discovery', my client app works correctly.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/1/2178a27dcb463a14bad2e2d9f6cdab9cb6a16a50.png)

---

<div class="post-metadata">

**Author:** ![charlie.ye](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@charlie.ye](https://forum.inductiveautomation.com/u/charlie.ye)\
**Post date:** [May 8, 2025, 12:03pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/26 "2025-05-08T12:03:00Z")

</div>

> [@Kevin.Herron](#):
>
> Alternatively, try setting the "Bind Addresses" setting for the Ignition OPC UA server to `0.0.0.0`. Remember to restart.

This works, but it is strange to me. Ignition OPC UA server has a bug here.

---

<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:** [May 8, 2025, 12:35pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/27 "2025-05-08T12:35:17Z")

</div>

> [@charlie.ye](#):
>
> Ignition OPC UA server has a bug here.

You may think so, but you haven't supported that, IMNSHO.

Do a domain name lookup on `localhost` in your environment. I bet it has been modified to not return `127.0.0.1` like it is supposed to.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 8, 2025, 12:41pm UTC](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912/28 "2025-05-08T12:41:30Z")

</div>

Ok, try setting the "Bind Addresses" back to just `localhost`, and then go modify the "Endpoint Addresses" setting to be `<hostname>,<localhost>,localhost`. Remember to restart.

It would also be useful if you shared the output of the UaStackServer logger from the Ignition logs during the OPC UA module startup sequence. It looks something like this:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/d/1d46746cefd6962ca0a30220321d4e899538c488.png)

> [@charlie.ye](#):
>
> Ignition OPC UA server has a bug here.

The Prosys monitor connects. Ignition's client connects. UaExpert connects.

if every other client and SDK can connect, but yours can't, maybe the bug isn't in the server...

[Previous page](https://forum.inductiveautomation.com/t/i-cannot-connect-to-ignition-server-from-c-c-codes/105912.md?page=1)
