1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| ##!/usr/bin/python
# -*- coding: utf-8 -*-
#Création Serveur en python
#Création appli_graphique avec Tkinter
from Tkinter import *
import tkMessageBox
import time
import socket,sys,platform,subprocess,serial
import multiprocessing
from multiprocessing import Process, Pipe
def appgraphique():
window = Tk()
window.title('Grille du Loto')
width, height = window.winfo_screenwidth(), window.winfo_screenheight()
window.overrideredirect(1)
window.geometry("%dx%d+0+0" % (width, height))
w = Canvas(window, width=width, height=height-20, bg='black')
def Affiche(): tkMessageBox.showinfo("Fichier","Aucun Fichier pour le moment")
def Affiche(): tkMessageBox.showinfo("Enregistrer","Aucun Enregistrement")
def About(): tkMessageBox.showinfo("A propos","Version 1.0")
def Affichegrille(nombre):
#print str(width) + " " + str(height)
h= (height-20)/9
larg=(width-20)/10
for i in range (0,10) :
for j in range (0,11):
if(nombre == ((i-1)*10+j)):
w.create_rectangle((j-1)*larg,(i-1)*h,(j)*larg,(i)*h,fill="red")
w.create_text((j-0.5)*larg,(i-0.5)*h,text=str((i-1)*10+j),font=("Purisa",54),fill="white")
else:
w.create_rectangle((j-1)*larg,(i-1)*h,(j)*larg,(i)*h,fill="grey")
w.create_text((j-0.5)*larg,(i-0.5)*h,text=str((i-1)*10+j),font=("Purisa",54),fill="white")
w.pack()
mainmenu = Menu(window)
menu1 = Menu(mainmenu)
menu1.add_command(label="Quitter", command=window.quit)
menuHelp = Menu(mainmenu) ## Menu Fils
menuHelp.add_command(label="A propos", command=About)
mainmenu.add_cascade(label = "Options", menu=menu1)
mainmenu.add_cascade(label = "Aide", menu=menuHelp)
window.config(menu = mainmenu)
Affichegrille(6)
mainloop()
def serveur():
IP = "192.168.0.103" #Adresse du serveur
PORT = 10500 # Port de Connexion du Serveur
counter =0 #Compteur de connexion
host = socket.gethostname()
NomOS = platform.system() #subprocess.call(['./trame_afficheur.py'])
#with open ("numero.txt", "r") as myfile:
# data=myfile.read().replace('\n', '')
trame=str()
trame_debut=str("\x02001\x1D001\x1D")
trame_message=str("birnve,nur")
trame_fin=str("\x03")
trame_affiche=str("\x01001\x1D001\x04")
ser=serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS
)
serveur_loto_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #Serveur Socket
print "Ecoute du port : " + str(PORT)
print ("Démarrage...")
try:
serveur_loto_socket.bind((IP, PORT)) #Fonction Bind association d'un socket avec une adresse ou un port donnée
except socket.error :
print "Echec.Erreur" + str(socket.error)
sys.exit
print "Nom de la machine :",host
print "OS: ", NomOS
#open('numero.txt', 'w').close()
# Mise en Attente du socket// Attente de la requête
print("Serveur en marche...Attente de requêtes.....")
serveur_loto_socket.listen(2)
connexion, adr = serveur_loto_socket.accept()
counter +=1
print "Nombre de connexions : ",counter
print ("Client connecté, adrese IP %s , port %s" % (adr[0], adr[1]))
while 1:
# Mise en Attente du socket// Attente de la requête
#etablissement d'une connection
#Acceptation de la connection
#counter +=1
#print "Nombre de socket:",counter
#print("Client connecté, adresse IP %s, port %s" % (adr[0], adr[1]))
data = connexion.recv(4)
if(data=="0"):
#counter =0
#data = "arret du tirage "
print "arrete"
trame_message = "ARRET DU TIRAGE "
trame=trame_debut+trame_message+trame_fin
ser.write(trame)
ser.write(trame)
ser.write(trame_affiche)
else:
#Affichegrille(data)
serveur_loto_socket.connect('tcp:127.0.0.1:5000')
serveur_loto_socket.sendto(data,'127.0.0.1:5000')
print "recu du message:", data
trame_message = "Num:" +data+ " "
trame = trame_debut + trame_message + trame_fin
ser.write(trame)
ser.write(trame)
ser.write(trame_affiche)
print("Fin de Connexion...")
#ser.close()
#connexion.close()
#com_process=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#com_process.bind(serveur,appgraphique)
#com_process.
Mon_serveur = multiprocessing.Process(target=serveur)
Mon_application = multiprocessing.Process(target=appgraphique)
Mon_serveur.start()
Mon_application.start()
Mon_serveur.join()
Mon_application.join() |
Partager