Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open connection with custom socket #873

Open
LibraryRaven opened this issue Nov 28, 2024 · 0 comments
Open

open connection with custom socket #873

LibraryRaven opened this issue Nov 28, 2024 · 0 comments
Labels
Status: Available No one has claimed responsibility for resolving this issue.

Comments

@LibraryRaven
Copy link

LibraryRaven commented Nov 28, 2024

Feature Description

I would like to be able to connect with a manually provided socket.

This would enable me to tunnel MQTT through an SSH connection with paramiko.

import paramiko

# connect to SSH gateway
sshclient = paramiko.SSHClient()
sshclient.connect("sshgateway.example.org", "user", "password")

def create_socket():
  # open tunnel to the internal MQTT port
  return sshclient.get_transport().open_channel('direct-tcpip', ("127.0.0.1", 1883), ('', 0))

import paho.mqtt.client as mqtt
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqttc.connect("127.0.0.1", transport="callback", create_socket=create_socket) 

Requested Solution

import socket

def create_socket():
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  sock.connect(('mqtt.example.org', 1883))
  return sock

import paho.mqtt.client as mqtt
mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2)
mqttc.connect("mqtt.example.org", transport="callback", create_socket=create_socket) 

Alternatives

For now, I can use my own SocketedClient class, which inherits Client and uses a provided create_socket function on connect() and reconnect().

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

1 participant