Skip to content

Commit eb7af29

Browse files
committed
add client-with-encryption.py example
1 parent 797abf1 commit eb7af29

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

‎examples/client-with-encryption.py‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
sys.path.insert(0, "..")
3+
import logging
4+
5+
from IPython import embed
6+
7+
from opcua import Client
8+
9+
10+
if __name__ == "__main__":
11+
logging.basicConfig(level=logging.WARNING)
12+
client = Client("opc.tcp://localhost:4840/freeopcua/server/")
13+
#client = Client("opc.tcp://localhost:53530/OPCUA/SimulationServer/")
14+
client.set_security_string("Basic256Sha256,SignAndEncrypt,certificate-example.der,private-key-example.pem")
15+
client.application_uri = "urn:example.org:FreeOpcUa:python-opcua"
16+
client.secure_channel_timeout = 10000
17+
client.session_timeout = 10000
18+
try:
19+
client.connect()
20+
root = client.get_root_node()
21+
objects = client.get_objects_node()
22+
print("childs og objects are: ", objects.get_children())
23+
24+
embed()
25+
finally:
26+
client.disconnect()

‎examples/server-with-encryption.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
server = Server()
1313
server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
1414

15+
server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt])
1516
# load server certificate and private key. This enables endpoints
1617
# with signing and encryption.
1718
server.load_certificate("certificate-example.der")

0 commit comments

Comments
 (0)