Skip to main content

Connection Troubleshooting

ua.Connect() If it fails OpcUaException, just look at it ex.StatusCode to pinpoint the location.

Further Reading

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​

StatusCodeRoot CauseResolve
BadConnectionRejectedThe server is not listening on port 4840Verify that the Server process has started
BadCommunicationErrorNo Internet connection / Blocked by firewalltelnet host 4840, disable the firewall
BadTcpEndpointUrlInvalidURL Spelling errorCheck opc.tcp://host:port
BadTcpServerTooBusyServer connection limit reachedReuse Sessions to Reduce Concurrency
BadSecurityModeRejectedMode is not supportedGetEndpoints See actual support
BadSecurityPolicyRejectedPolicy Not SupportedServer enabled Basic256Sha256
BadCertificateInvalidCertificate has expired / is not yet validRegenerate
BadCertificateUntrustedThe server does not trust the clientClient .der Copy to Server trusted/
BadCertificateUriInvalidSAN URI ≠ ApplicationUriStandardize when regenerating certificates
BadCertificateHostNameInvalidConnect to host ≠ SAN.DNSUse "and IP" or "or" DNS SAN
BadCertificateTimeInvalidClock deviation > ~10 minutesNTP Synchronize
BadIdentityTokenInvalidUserToken Missing fieldCheck that the username and password are not empty
BadIdentityTokenRejectedThe user does not exist or the password is incorrect.Server-Side Account Management
BadUserAccessDeniedThe user does not have connection permissions.Server-side ACL
BadTimeoutConnection / Handshake TimeoutAdd 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.