from os import popen from socket import * from sys import argv from threading import * from term import Color from str import toArray terminal = Color() clients = [] def broadcast (message): global clients for i in clients: i[0].send (message) def listernerController (clientsocket): buff = True BUFFER_SIZE = 1024 client_info = clientsocket[0].recv (BUFFER_SIZE) while buff != None: buff = clientsocket[0].recv (BUFFER_SIZE) value = toArray (buff, ':') if value[0] == 'message': print (client_info + " says: " + value[1]) broadcast ('Client '+client_info+' says: '+value[1]) elif value[0] == 'command': if value[1] != 'exit': print ('Executing '+ value[1]+" for client: "+client_info) broadcast (popen (value[1]).read())
import os import sys from term import Color term = Color() debug = False if len (sys.argv) > 1: if sys.argv[1] == 'debug': debug = True def getDivisores(n): divisores = [] for i in range(n): if i > 0 and (n % i) == 0: divisores.append(i) return (divisores) def isPerfect (n): divisores = getDivisores (n) sigma = 0 if debug: term.cout ('white', 'Divisors: ') for i in divisores: term.cout ('warning', str (i))
from socket import * from sys import argv from threading import * from term import Color from str import toArray terminal = Color() def listernerController (serversocket): buff = True BUFFER_SIZE = 1024 while buff != 'shutdown': buff = serversocket.recv (BUFFER_SIZE) print (buff) def client (server, port, debug = False): if debug: print ('Criando socket de cliente...') sck = socket (AF_INET, SOCK_STREAM) if debug: print ("\t\tOK") print ('Connectando cliente ao servidor ('+server+', '+str(port)+')' ) sck.connect ( (server, port) ) sck.send (sck.getsockname()[0]) Thread (target=listernerController, args=(sck,)).start () buff = True mode = 'message' while buff != 'exit': buff = raw_input (mode+":") aux = toArray (buff, ':')