Connection Troubleshooting
ua.Connect() If it fails OpcUaException, just look at it ex.StatusCode to pinpoint the location.
- Encryption Configuration — Sign / SignAndEncrypt Hands-On
- Required Environment — Network / NTP / Server Selection
5-Level Investigation (Bottom-Up)
TCP Layer — Is the network connected?
ping <host>
telnet <host> 4840 # or nc -zv <host> 4840
No connection → Check the firewall / NAT / VPN. If this happens across multiple computers, try turning off the firewall first.
OpenSecureChannel Layer — Ports and endpoints can establish a connection
First, use the simplest combination (None + Anonymous) to rule out encryption:
using var ua = new DarraOpcUa("opc.tcp://host:4840");
ua.Connect();
Success → Network and server are both OK; any subsequent issues are related to encryption or authentication. Failure → Refer to the quick reference table StatusCode.
Endpoint Negotiation Layer — Does the server support the Mode/Policy requested by the client?
var endpoints = OpcUaDiscovery.GetEndpoints("opc.tcp://host:4840");
foreach (var ep in endpoints)
Console.WriteLine($"{ep.SecurityMode} | {ep.SecurityPolicyUri}");
You can only use combinations that actually appear in the list.
Certificate Layer — Mutual Trust in Both Directions
If None works, but Sign / doesn't SignAndEncrypt, move on Encryption Configuration:
- Client Certificate SAN.URI = ApplicationUri
- The server's "trusted/" directory contains the client.
.der - Time Synchronization (Rejected if deviation exceeds ~10 minutes)
Session Layer — User Identity
new DarraOpcUa(url); // anonymous
new DarraOpcUa(url, username: "admin", password: "x"); // username
BadIdentityTokenRejected → The server username/password is incorrect.
BadUserAccessDenied → The account exists but does not have ConnectSession permissions; modify the server settings ACL.
StatusCode Quick Reference
| StatusCode | Root Cause | Resolve |
|---|---|---|
| BadConnectionRejected | The server is not listening on port 4840 | Verify that the Server process has started |
| BadCommunicationError | No Internet connection / Blocked by firewall | telnet host 4840, disable the firewall |
| BadTcpEndpointUrlInvalid | URL Spelling error | Check opc.tcp://host:port |
| BadTcpServerTooBusy | Server connection limit reached | Reuse Sessions to Reduce Concurrency |
| BadSecurityModeRejected | Mode is not supported | GetEndpoints See actual support |
| BadSecurityPolicyRejected | Policy Not Supported | Server enabled Basic256Sha256 |
| BadCertificateInvalid | Certificate has expired / is not yet valid | Regenerate |
| BadCertificateUntrusted | The server does not trust the client | Client .der Copy to Server trusted/ |
| BadCertificateUriInvalid | SAN URI ≠ ApplicationUri | Standardize when regenerating certificates |
| BadCertificateHostNameInvalid | Connect to host ≠ SAN.DNS | Use "and IP" or "or" DNS SAN |
| BadCertificateTimeInvalid | Clock deviation > ~10 minutes | NTP Synchronize |
| BadIdentityTokenInvalid | UserToken Missing field | Check that the username and password are not empty |
| BadIdentityTokenRejected | The user does not exist or the password is incorrect. | Server-Side Account Management |
| BadUserAccessDenied | The user does not have connection permissions. | Server-side ACL |
| BadTimeout | Connection / Handshake Timeout | Add connectTimeoutMs |
Enable debug logging
Let's see which step of the handshake went wrong:
Logging.SetLevel(LogLevel.Debug);
Logging.OnLog += (level, msg) => Console.WriteLine($"[{level}] {msg}");
Or environment variables OPCUA_LOG_LEVEL=Debug. It will print "Hello" / OpenSecureChannel / GetEndpoints / CreateSession / the RequestId for each ActivateSession step and StatusCode.
If you really can't pinpoint the source, use Wireshark to capture traffic on port 4840 and view the messages directly using the built-in OPC UA dissector.
Related Links
- Encryption Configuration — Sign / SignAndEncrypt Hands-On
- Required Environment — Network / NTP / Server Selection
- Basics — Security Models
- Quick Start — Enable Encryption