Slightly more technical question.
I have a little python service that I’m trying to open to the world, I’m using the latest playit-cli from from github (v1.0.0-rc2) and its
launch command to use a configuration file.
This is the configuration file:
agent_name = "web3MC" secret_path = "./../secrets/secrets.txt" command = "python3" command_args = ["./../python/python_server.py"] # 9e0a3886-8b6d-403a-9755-1d67987eb440=192.168.1.20:25565 [[tunnels]] name = "YesheyTunnel" proto = "both" port_count = 2 local = 45637 special_lan = true
When I run it with
playit-cli launch ./config.toml this it creates this tunnel and runs the pythonic server:
As you can see, the Local Port for the tunnel got auto assigned, in
this case to 62026. I expected it to be 45637 as defined in the
localparameter in the config file, but maybe that option is something else?
My python server listens on port 45637.
When I try to connect a client to the tunnel address
mean-street.at.ply.gg in port 45637 it doesn’t work, I need to specify in the client the auto-generated port 62026 or change that port in the site for it to connect.
What puzzles me is that if I do the same but launch a minecraft server instead of my python server (and set the tunnel
local port to 25565 in the config file), I’m able to join the minecraft server with a client without specifying the auto generated port, in this case, in the minecraft client, I’d be able to join with mean-street.at.ply.gg or with mean-street.at.ply.gg:62026.
What I want is to also be able to connect to my python server with a python client without having to specify the port (or have a predefined port that the server can set through the config file instead of being auto assigned and connect to that one)
So the questions are:
- Can I set the tunnel Local Port programmatically through the config file or without having to go to the site?
- If not, what does the
tunnelsin the configuration file do, and can I use it to set a constant port so the client always knows which port it needs to connect to?
- How does the Minecraft client know which port it should connect to when it is given just the tunnel address?
This is my test python_server.py:
import socket import threading def server_program(): # get the hostname host = "127.0.0.1" port = 45637 # initiate port no above 1024 print(port) server_socket = socket.socket() # get instance # look closely. The bind() function takes tuple as argument server_socket.bind((host, port)) # bind host address and port together # configure how many client the server can listen simultaneously server_socket.listen(2) conn, address = server_socket.accept() # accept new connection print("Connection from: " + str(address)) while True: # receive data stream. it won't accept data packet greater than 1024 bytes data = conn.recv(1024).decode() if not data: # if data is not received break break print("from connected user: " + str(data)) data = input(' -> ') conn.send(data.encode()) # send data to the client conn.close() # close the connection if __name__ == '__main__': server_program()
this is my test python_client.py:
import socket def client_program(): host = "listed-washing.at.ply.gg" # as both code is running on same pc port = 45637 # socket server port number client_socket = socket.socket() # instantiate client_socket.connect((host, port)) # connect to the server message = input(" -> ") # take input while message.lower().strip() != 'bye': client_socket.send(message.encode()) # send message data = client_socket.recv(1024).decode() # receive response print('Received from server: ' + data) # show in terminal message = input(" -> ") # again take input client_socket.close() # close the connection if __name__ == '__main__': client_program()
For a little more context, this is for this project
thanks in advance