Skip to content

Instantly share code, notes, and snippets.

@wisnubaldas
Last active May 12, 2022 08:34
Show Gist options
  • Save wisnubaldas/8bcedb8dd2f3739c722e4c1ed8e44efa to your computer and use it in GitHub Desktop.
Save wisnubaldas/8bcedb8dd2f3739c722e4c1ed8e44efa to your computer and use it in GitHub Desktop.

Revisions

  1. wisnubaldas renamed this gist May 12, 2022. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. wisnubaldas created this gist May 12, 2022.
    34 changes: 34 additions & 0 deletions kerong_command
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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()