Anonymous Anonymous - 20 days ago
61 0

socket listen script

Python

socket listen script

import socket
import subprocess
import sys

def Main():
    host = "xxx.xx.xx.xx" #my actual IP
    port = 5000

    mySocket = socket.socket()
    mySocket.bind((host,port))

    mySocket.listen(1)
    conn, addr = mySocket.accept()

    print ("Connection from: " + str(addr))
    while True:
            data = conn.recv(1024).decode()
            if not data:
                    break
            print ("from connected  user: " + str(data))

            data = str(data).upper()
            print ("sending: " + str(data))
            conn.send(data.encode())

    conn.close()

if __name__ == '__main__':
    Main()