0

Before I start I want to say that i'm 14 and this might or might not sound dumb. So I was working on a python project and I'm almost done with it but except 1 part. I want to make this:

"Make the socket, handle the connection to it, then send your menu over the socket" Can someone help me with this? I 'made' an socket already.

This is the code -->

#!/usr/bin/env python3

import socket

HOST = '46.101.xxx.xxx'  
PORT = 65432        

printed = False

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.bind((HOST, PORT))
    s.listen()
    conn, addr = s.accept()
    with conn:
        print('Connected by', addr)
        while True:
            data = conn.recv(1024)
            if not data:
                if not printed:
                  print('Disconnected by', addr)
                  printed = True
            conn.sendall(data)
Edlirr
  • 1
  • 1
  • Exactly, only thing is the 'server' will be an Linux VPS + other people need to be able to connect to the server and let the python script run automatically. – Edlirr Feb 14 '21 at 18:39
  • Not really, I heard something of the command called 'screen' on Linux operating systems. Also, an example would be how botnets nowadays work. U just connect through the vps IP + port, and it would just screen the .go file. Like that menu, that's what I need but instead it'll run a Python file. – Edlirr Feb 15 '21 at 12:37
  • I asked someone that did this before, he answered with this: You just setup a socket and have it listen – Edlirr Feb 15 '21 at 12:39
  • If that's what you want, you can indeed have your python script listen on a port and have it dump some contents onto the port, when someone connects to it. But I'm not sure it that's what you want. Your question is quite unclear. – Martin Prikryl Feb 15 '21 at 12:45
  • Yes, i'm from an different country so it's hard to explain. Basically what I want is this 1) User connects through IP & different port 2) Python file runs. – Edlirr Feb 15 '21 at 12:49
  • That's not what I wrote. If you want *something* to run a Python script, when a user connects to a port, then you need the *something*. That's not a programming question. And it's not a trivial question either. You can ask that on [su]. – Or you can implement the *something* yourself. It can be another Python script. – Or you can make the Python script itself run continuously on the server, listening on the port and returning some contents, when something connects to the port. Basically merge the *something* and the script into one script. – Martin Prikryl Feb 15 '21 at 13:10
  • Hey, sorry for this but uhm. I setup a socket that is listening, so when someone connects through it it just works. But I want if someone connects through the IP and port where the socket is listening, it would run a file that displays ON the PuTTY screen. – Edlirr Feb 15 '21 at 15:59
  • Can I give u the code I setup? – Edlirr Feb 15 '21 at 16:00
  • Just did that ! – Edlirr Feb 15 '21 at 18:29

0 Answers0