1- """
1+ # Fend TCP and UDP Client/Server Example Python Test Scripts
2+ # Copyright (c) 2023 Fend Incorporated. All rights reserved.
3+
4+ """
25This is an example Python script provided to aid in the integration of a Fend Data Diode in a TCP Client/Server application.
36
47For this example a simple socket is extabilshed with the diode's TCP server and a test message is continuously sent to the input side
1114For these scripts to function, the diode will need to be setup in TCP Client/Server mode. Please see the user manual
1215on instruction for this setup process.
1316
14- These scripts will continuously run until aborted.
17+ These scripts will continuously run until aborted.
1518
1619The following is the expected step by step process of what the script does:
17201. The script creates a socket object named "client".
18212. A connection attempt to the diode is made.
19223. If the connection is made, the script enters a sending loop.
20- 4. This loop will check to see if the data is larger than 1460 bytes. If so, it will get a chunk and send that.
23+ 4. This loop will check to see if the data is larger than 1460 bytes. If so, it will get a chunk and send that.
21245. The script will then wait for the diode to send its ACK before proceeding.
22256. The loop will continue until all the data has been chunked and transmitted.
23267. The script waits 1 second.
3033from timeit import default_timer
3134
3235# Change this to the IP address of your diode's Input Side IP Address.
33- diodeInputSideIP = "192.168.1.99"
36+ diodeInputSideIP = "192.168.1.99"
3437
3538# Change this to the Diode TCP Server Port in your diode's Input Side TCP Passthrough Settings.
36- diodeTcpPassthroughPort = 50000
39+ diodeTcpPassthroughPort = 50000
3740
3841# create a socket
3942client = socket .socket (socket .AF_INET , socket .SOCK_STREAM )
4851try :
4952 while True :
5053 # Send data to diode
51- if len (data ) > 1460 : # If the data you wish to send is larger than 1460 bytes, you need to chunk.
54+ if len (data ) > 1460 : # If the data you wish to send is larger than 1460 bytes, you need to chunk.
5255 index = 0
5356 while index < len (data ):
5457 # Create chunk of 1460 chars
5558 chunk = data [index : index + 1460 ]
56-
59+
5760 # Send chunk to the diode's TCP server
5861 client .send (chunk .encode ())
5962
8184except TimeoutError :
8285 print ("No response was received from the diode. Please check your settings and try again." )
8386finally :
84- client .close ()
87+ client .close ()
0 commit comments