Passa al contenuto principale

Esempi di codice


# Tecnoteam (SC) 2022.07.15
#
# Ver 1.0.1.1 - 2022.07.15
#    First version based on Ethernet_Specola 1.0.1
# 

import socket

HOST = "192.168.250.1"  # The server's hostname or IP address - Omron default IP: 192.168.250.1
PORT = 9630             # The port used by the server - Tecnoteam default port: 9630

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    print(f"Connecting to {HOST} on port {PORT} ... ", end="")
    s.connect((HOST, PORT))
    print("OK")
    while True:
        value = input("Insert string to send ('quit' to exit): ")
        if value == "quit" or len(value) == 0:
            break
        s.send(str.encode(value))
        data = s.recv(1024).decode("utf-8")
        data = data.replace(b'\x06'.decode("utf-8"), '[ACK]').replace(b'\x15'.decode("utf-8"), '[NAK]')
        print(f"Received: {data}")