Skip to content

Commit

Permalink
docs: Python comment for non-Mit licensed code
Browse files Browse the repository at this point in the history
  • Loading branch information
TechSolomon committed Apr 22, 2024
1 parent 8f1629e commit 4bed208
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BIN_NAME=diode
BIN_VERSION=0.1.2
BIN_VERSION=0.1.3
BIN_DATE=$(shell date +%FT%T%z)

all: build
Expand Down
19 changes: 11 additions & 8 deletions sample/FendTcpClientExample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
# Fend TCP and UDP Client/Server Example Python Test Scripts
# Copyright (c) 2023 Fend Incorporated. All rights reserved.

"""
This is an example Python script provided to aid in the integration of a Fend Data Diode in a TCP Client/Server application.
For this example a simple socket is extabilshed with the diode's TCP server and a test message is continuously sent to the input side
Expand All @@ -11,13 +14,13 @@
For these scripts to function, the diode will need to be setup in TCP Client/Server mode. Please see the user manual
on instruction for this setup process.
These scripts will continuously run until aborted.
These scripts will continuously run until aborted.
The following is the expected step by step process of what the script does:
1. The script creates a socket object named "client".
2. A connection attempt to the diode is made.
3. If the connection is made, the script enters a sending loop.
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.
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.
5. The script will then wait for the diode to send its ACK before proceeding.
6. The loop will continue until all the data has been chunked and transmitted.
7. The script waits 1 second.
Expand All @@ -30,10 +33,10 @@
from timeit import default_timer

# Change this to the IP address of your diode's Input Side IP Address.
diodeInputSideIP = "192.168.1.99"
diodeInputSideIP = "192.168.1.99"

# Change this to the Diode TCP Server Port in your diode's Input Side TCP Passthrough Settings.
diodeTcpPassthroughPort = 50000
diodeTcpPassthroughPort = 50000

# create a socket
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
Expand All @@ -48,12 +51,12 @@
try:
while True:
# Send data to diode
if len(data) > 1460: # If the data you wish to send is larger than 1460 bytes, you need to chunk.
if len(data) > 1460: # If the data you wish to send is larger than 1460 bytes, you need to chunk.
index = 0
while index < len(data):
# Create chunk of 1460 chars
chunk = data[index : index + 1460]

# Send chunk to the diode's TCP server
client.send(chunk.encode())

Expand Down Expand Up @@ -81,4 +84,4 @@
except TimeoutError:
print("No response was received from the diode. Please check your settings and try again.")
finally:
client.close()
client.close()
25 changes: 14 additions & 11 deletions sample/FendTcpServerExample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
# Fend TCP and UDP Client/Server Example Python Test Scripts
# Copyright (c) 2023 Fend Incorporated. All rights reserved.

"""
This is an example Python script provided to aid in the integration of a Fend Data Diode in a TCP Client/Server application.
For this example a simple socket is opened and listens for the diode's TCP client to connect. When data is received it is printed to
Expand All @@ -7,7 +10,7 @@
For these scripts to function, the diode will need to be setup in TCP client/server mode. Please see the user manual
on instruction for this setup process.
These scripts will continuously run until aborted.
These scripts will continuously run until aborted.
The following is the expected step by step process of what the script does:
1. The script creates a socket object named "server".
Expand All @@ -18,35 +21,35 @@
"""

import socket

# Change this to the Target TCP Server IP Address in your diode's Output Side TCP Client Settings.
targetTcpServerIP = "192.168.1.20"

# Change this to the Target TCP Server Port in your diode's Output Side TCP Client Settings.
targetTcpServerPort = 503
targetTcpServerPort = 503

# Set up a TCP server
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((targetTcpServerIP, targetTcpServerPort))

# Begin listening
server.listen(1)

while True:
print("Waiting for connection")
connection, client = server.accept()

try:
# Print to console the connected client IP address
print("Connected to client IP: {}".format(client))

# Receive and print data 10 Kbytes at a time, as long as the client is sending something
while True:
data = connection.recv(10240)
print(f"Received data: {data.decode()}")

if not data:
break

finally:
connection.close()
connection.close()
19 changes: 11 additions & 8 deletions sample/FendUdpClientExample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
# Fend TCP and UDP Client/Server Example Python Test Scripts
# Copyright (c) 2023 Fend Incorporated. All rights reserved.

"""
This is an example Python script provided to aid in the integration of a Fend Data Diode in a UDP Client/Server application.
For this example a simple socket is extabilshed with the diode's UDP server and a test message is continuously sent to the input side
Expand All @@ -11,12 +14,12 @@
For these scripts to function, the diode will need to be setup in UDP Client/Server mode. In addition, the "Reply with an ACK" option
must be selected. Please see the user manualon instruction for this setup process.
These scripts will continuously run until aborted.
These scripts will continuously run until aborted.
The following is the expected step by step process of what the script does:
1. The script creates a socket object named "client".
2. The script enters the sending loop.
3. This loop will check to see if the data is larger than 1460 bytes. If so, it will get a chunk and send that.
3. This loop will check to see if the data is larger than 1460 bytes. If so, it will get a chunk and send that.
4. The script will then wait for the diode to send its ACK before proceeding.
5. The loop will continue until all the data has been chunked and transmitted.
6. The script waits 1 second.
Expand All @@ -29,10 +32,10 @@
from timeit import default_timer

# Change this to the IP address of your diode's Input Side IP Address.
diodeInputSideIP = "192.168.1.99"
diodeInputSideIP = "192.168.1.99"

# Change this to the Diode UDP Server Port in your diode's Input Side UDP Passthrough Settings.
diodeUDPPassthroughPort = 50000
diodeUDPPassthroughPort = 50000

# create a socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Expand All @@ -47,12 +50,12 @@
try:
while True:
# Send data to diode
if len(data) > 1460: # If the data you wish to send is larger than 1460 bytes, you need to chunk.
if len(data) > 1460: # If the data you wish to send is larger than 1460 bytes, you need to chunk.
index = 0
while index < len(data):
# Create chunk of 1460 chars
chunk = data[index : index + 1460]

# Send chunk to the diode's UDP server
client.send(chunk.encode())

Expand Down Expand Up @@ -80,4 +83,4 @@
except TimeoutError:
print("No response was received from the diode. Please check your settings and try again.")
finally:
client.close()
client.close()
15 changes: 9 additions & 6 deletions sample/FendUdpServerExample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
# Fend TCP and UDP Client/Server Example Python Test Scripts
# Copyright (c) 2023 Fend Incorporated. All rights reserved.

"""
This is an example Python script provided to aid in the integration of a Fend Data Diode in a UDP Client/Server application.
For this example a simple socket is opened and listens for the diode's UDP client to connect. When data is received it is printed to
Expand All @@ -7,7 +10,7 @@
For these scripts to function, the diode will need to be setup in UDP client/server mode. Please see the user manual
on instruction for this setup process.
These scripts will continuously run until aborted.
These scripts will continuously run until aborted.
The following is the expected step by step process of what the script does:
1. The script creates a socket object named "server".
Expand All @@ -17,17 +20,17 @@
"""

import socket

# Change this to the Target UDP Server IP Address in your diode's Output Side UDP Client Settings.
targetUDPServerIP = "192.168.1.20"

# Change this to the Target UDP Server Port in your diode's Output Side UDP Client Settings.
targetUDPServerPort = 503
targetUDPServerPort = 503

# Set up a UDP server
server = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server.bind((targetUDPServerIP, targetUDPServerPort))

# Receive and print data 10 Kbytes at a time, as long as the client is sending something
try:
while True:
Expand All @@ -37,4 +40,4 @@
if not data:
break
finally:
server.close()
server.close()

0 comments on commit 4bed208

Please sign in to comment.