(Socket) Client and Server Connection - how to get return from Cmd- Client (Python)

1

I want to run a command in the client's Cmd and return the values to the server. I've already been able to run the command in the client's Cmd ... Now how do I return the values to the server?

The Server:

import socket
import os


Host = "127.0.0.1" #str(input("Host: "))
Door = 8291        #int(input("Door: "))

conexao = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

conexao.bind((Host,Door))
conexao.listen(2)

c, e = conexao.accept()

while True:

    os.system('cls')

    print("Connected to : ", e)

    print("\n\n")

    print("|----------------|-------|")
    print("|  Instructions  | Press |")
    print("|----------------|-------|")
    print("|  Send Message  |   1   |")
    print("|----------------|-------|")
    print("|  Send CodeDos  |   2   |")
    print("|----------------|-------|")

    print("\n\n")

    Choice = int(input("I Pick: "))

    os.system("cls")

    if Choice == 1:

        Msg = input("Message:")
        c.send("1".encode('ascii'))
        c.send(Msg.encode('ascii'))


    elif Choice == 2:

        Cod = input("CodeDos:")
        c.send("2".encode('ascii'))
        c.send(Cod.encode('ascii'))


    else:

        print("Faill")
        os.system('pause')

The client:

import socket
import os


Host = "127.0.0.1" #str(input("Host: "))
Door = 8291        #int(input("Door: "))

conexao = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

conexao.connect((Host,Door))

while True:

    info = conexao.recv(1024)

    if info.decode('ascii') == "1":   # If Choice == 1 (Message) Do:

        info = conexao.recv(1024)

        info = info.decode('ascii')

        print(info)

    elif info.decode('ascii') == "2": # If Choice == 2 (CodeDos) Do:

        info = conexao.recv(1024)

        info = info.decode('ascii')

        os.system(info)
    
asked by anonymous 31.03.2018 / 03:31

0 answers