Last active
December 24, 2021 10:55
-
-
Save jamby1100/faf10bbd148e500f9fb20c4f7274cd24 to your computer and use it in GitHub Desktop.
This snippet is based off the work of Mathew Wachter (https://github.com/matthewwachter/py-tcp-threaded-server). I added modifications to allow it to communicate to Lambda via requests
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 json | |
import socket | |
import os | |
# Create a TCP/IP socket | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
# Connect the socket to the port where the server is listening | |
ip_address = os.getenv("TCP_SERVER_IP_ADDRESS") | |
port = int(os.getenv("TCP_PORT_NUMBER")) | |
server_address = (ip_address, port) | |
sock.connect(server_address) | |
msg = 'this is the request' | |
# msg = json.dumps(data) | |
# Send the message | |
sock.sendall(msg.encode('utf-8')) | |
# Receive the message back | |
res = sock.recv(1024).decode('utf-8') | |
print("AND THE RESPONSE IS") | |
print(res) | |
data = json.loads(res) | |
print(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment