Last active
May 12, 2022 08:34
-
-
Save wisnubaldas/8bcedb8dd2f3739c722e4c1ed8e44efa to your computer and use it in GitHub Desktop.
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 sys | |
# 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 | |
server_address = ('192.168.123.49', 5000) | |
print(sys.stderr, 'connecting to %s port %s' % server_address) | |
sock.connect(server_address) | |
try: | |
sock.setblocking(True) | |
# Send data | |
# message = "02 00 31 03 36" | |
arr = bytes.fromhex('02 00 31 03 36') | |
print(len(arr)) | |
print(sys.stderr, 'sending "%s"' % arr) | |
sock.send(arr) | |
data = sock.recv(9) | |
print(sys.stderr, 'received "%s"' % data) | |
# Look for the response | |
# amount_received = 0 | |
# amount_expected = len(arr) | |
# print(amount_expected) | |
# while amount_received < amount_expected: | |
# data = sock.recv(14) | |
# amount_received += len(data) | |
# print(sys.stderr, 'received "%s"' % data) | |
finally: | |
print(sys.stderr, 'closing socket') | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment