PCController progress
import socket
import thread
ip = '127.0.0.1'
port = 26000
buffer = 24
def commands(data):
if data in ('shutdown', ' shutdown'): print 'it worked!'
def server_init():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((ip, port))
s.listen(5)
conn, addr = s.accept()
while True:
data = conn.recv(buffer)
if not data: break
print data
commands(data)
conn.close()
server_init()
#Imports
import CommandHandler
#Handles the main loop of the program.
#Basically just takes in the input and makes decisions based on the aforementioned
def Core_Loop():
while True:
#Syntax is as follows:
#!PC *COMMAND* for Power commands
#!CC *COMMAND* for Controller commands
#!LC *COMMAND* for Launch commands
print ('Enter command:')
c = raw_input()
type, command = c.split(' ')
#If's and elif's that handles the input
if type in ('!PC', ' !PC'):
CommandHandler.Power_Commands(command)
elif type in ('!CC', ' !CC'):
CommandHandler.Controller_Commands(command)
#elif type in ('!LC', ' !LC'):
#CommandHandler.Launch_Commands(command)
#Calls the loop
Core_Loop()
#Imports
import socket
#Global Variables
ip = '127.0.0.1'
port = 26000
#Handles all the power commands.
def Power_Commands(command):
#TCP connection handling
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip, port))
#If's and elif's that handles the command from main.py
if command in ('shutdown', ' shutdown'):
s.send('shutdown')
print ('Command shutdown has been executed')
elif command in ('restart', ' restart'):
#s.send('restart')
print ('Command restart has been executed')
elif command in ('sleep', ' sleep'):
#s.send('sleep')
print ('Command sleep has been executed')
s.close
def Controller_Commands(command):
#TCP connection handling
#If's and elif's
if command in ('ct', ' ct'):
print ('Controller test is working')
else:
print('Didnt work')
#def Launch_Commands(command):