Created
December 11, 2023 17:11
-
-
Save galenseilis/b833123d3c93eec27a021a7e60052101 to your computer and use it in GitHub Desktop.
socket_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import pickle | |
data_structure = {'key': 'value', 'numbers': [1, 2, 3]} | |
# Serialize the data structure | |
serialized_data = pickle.dumps(data_structure) | |
# Send the serialized data to script2.py | |
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | |
s.connect(('localhost', 12345)) | |
s.sendall(serialized_data) | |
# Receive the processed data from script2.py | |
received_data = s.recv(4096) | |
# Deserialize and print the processed data | |
processed_data = pickle.loads(received_data) | |
print("Processed data received from script2.py:", processed_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script2.py