Basic Telnet Connection Help
-
Hi all,
I am hoping to read basic telnet messages sent through M118. I am running my Duet in standalone mode and it is directly connected to my pc. I am trying to use the socket library in python to listen for messages, but I am not having any luck. My basic config.g file contains the following:
global g = 0 M586 P2 S1 R23 M553 P255.255.255.0 M552 S1 P192.168.2.80
I am using the following macro to try to test the telnet messages:
set global.g = 0 while global.g < 20 M118 P4 S"message" set global.g = global.g + 1 G4 S3
And I am trying to use the following super basic Python script to listen:
import socket import sys sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_address = ('localhost', 23) sock.bind(server_address) sock.listen(1) while True: print(sys.stderr) print('waiting for a connection') connection, client_address = sock.accept()
If anybody could help me out I would definitely appreciate it. Thanks in advance!
-
@btmclain
I don't get what you're trying to do.Where are you running the python script? On your PC?
If so, it's listening, but there's nothing that is going to try to connect to your PC.
Maybe you want to run a python script on your PC that connects to the Duet's telent port?
-
@alankilian Hi thanks for the quick reply. To be honest I am not really sure what I am doing.
Yes I am running the python script from my PC.
I was under the impression that the Duet would send a message to the specified port on my pc. I am obviously mistaken. Let me try to connect to a telnet port on the duet and see how that goes.
-
@alankilian so I used the following line to try to connect to the machine:
sock = socket.create_connection((duet_host, 23), timeout=10)
I am getting this response: [WinError 10061] No connection could be made because the target machine actively refused it
Is there a security setting within the duet that is causing this to happen?
-
Looking HERE
I got this working:#!/usr/bin/env python3 import socket HOST = '192.168.0.104' # The server's hostname or IP address PORT = 23 # The port used by the server with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.connect((HOST, PORT)) data = s.recv(1024) print('Received', repr(data)) data = s.recv(1024) print('Received', repr(data))
192.168.0.104 is the IP address of my duet and I got several "message" printed from Python.
I'm not a Python guy, but you might get farther with this.
-
@alankilian That worked! Thank you very much for the help. I will run with it from here
-
@btmclain Excellent! Glad to be of service.
-
@btmclain which Duet are you using, and which firmware version?
You can run a program such as Putty on the PC to test the Telnet connection.
-
@dc42 We are using a Duet 3 MB 6HC with the latest firmware, 3.3 I believe? Alan's answer was perfect, it is exactly what I was looking for.
-
This post is deleted! -
-
-
@alankilian i know this topic is old but ive been looking into the same thing im trying to grab the macros from the duet but ive had no joy so far using python