From b5c2910898942835e13a202811d06ae8bf2e8227 Mon Sep 17 00:00:00 2001 From: Ghaith TABIB Date: Thu, 17 Aug 2017 20:33:00 +0100 Subject: [PATCH] initial prod commit --- Client/client.py | 24 +++---- Server/ClientThread/__init__.pyc | Bin 155 -> 0 bytes Server/ClientThread/clth.pyc | Bin 1834 -> 0 bytes Server/{ => lib}/ClientThread/__init__.py | 0 Server/{ => lib}/ClientThread/clth.py | 19 +++-- Server/{ => lib}/ClientThread/clth.py~ | 0 Server/lib/__init__.py | 0 Server/lib/server.py | 52 ++++++++++++++ Server/server | 42 ++++++++++++ Server/server.py | 80 ---------------------- Server/serverinterface/__init__.py | 1 - Server/serverinterface/__init__.pyc | Bin 158 -> 0 bytes Server/serverinterface/graphique.py | 50 -------------- Server/serverinterface/graphique.pyc | Bin 3153 -> 0 bytes Server/serverinterface/graphique.py~ | 51 -------------- Server/server~ | 80 ---------------------- 16 files changed, 115 insertions(+), 284 deletions(-) delete mode 100644 Server/ClientThread/__init__.pyc delete mode 100644 Server/ClientThread/clth.pyc rename Server/{ => lib}/ClientThread/__init__.py (100%) rename Server/{ => lib}/ClientThread/clth.py (60%) rename Server/{ => lib}/ClientThread/clth.py~ (100%) create mode 100644 Server/lib/__init__.py create mode 100644 Server/lib/server.py create mode 100644 Server/server delete mode 100644 Server/server.py delete mode 100644 Server/serverinterface/__init__.py delete mode 100644 Server/serverinterface/__init__.pyc delete mode 100644 Server/serverinterface/graphique.py delete mode 100644 Server/serverinterface/graphique.pyc delete mode 100644 Server/serverinterface/graphique.py~ delete mode 100644 Server/server~ diff --git a/Client/client.py b/Client/client.py index 824c371..23924ff 100644 --- a/Client/client.py +++ b/Client/client.py @@ -1,22 +1,22 @@ #!/usr/bin/env python -# (C) coded by Tabib Ghaith +# (C) coded by Tabib Ghaith import socket import threading from ClientInterface.graphique import * class Connect(threading.Thread): - + def __init__(self,sock): threading.Thread.__init__(self) # prepare the socket self.host = '127.0.0.1' - self.port = 5000 + self.port = 4141 self.sock = sock self.recvthread = threading.Thread(target=self.recv_data) def run(self): # let's begin ! Buffer.append("Connected To server "+str(self.host)+"\n-------------------------------------------") # start a receving thread - + self.recvthread.start() self.recvthread.join() def send(self,msg): @@ -26,7 +26,7 @@ def recv_data(self): while True: # ready to receives msg = self.sock.recv(1028) - if len(msg) == 0 : + if len(msg) == 0 : Buffer.append("\nConncetion lost") break Buffer.append("\n"+str(msg)) @@ -35,14 +35,14 @@ def stoping(self): self.sock.shutdown(socket.SHUT_WR) def conn(username): sock = socket.socket()# standard TCP protocole - - if sock.connect_ex(('127.0.0.1',5000)) == 0 : + + if sock.connect_ex(('127.0.0.1',4141)) == 0 : sock.send(username) return [True , sock ] else : sock.close() return [False , -1] - + def Main(): global Buffer Buffer = [] @@ -50,13 +50,13 @@ def Main(): login = log(conn) login.loop() MainSocket = login.sock - # - if MainSocket is not None : + # + if MainSocket is not None : user = Connect(MainSocket) user.start() fen = app(Buffer,user.stoping,user.send) fen.loop() user.stoping() - + if __name__ == '__main__': - Main() + Main() diff --git a/Server/ClientThread/__init__.pyc b/Server/ClientThread/__init__.pyc deleted file mode 100644 index 67690981f4c64bb7978af2def3d1397a7213d6af..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 155 zcmZSn%*!QnDnBxr0SXv_v;zc_kqkMX8A?`tk9Zd6^~g a@p=W7B^*G5Y;yBcN^?@}K-LulF#`Z5k0bg3 diff --git a/Server/ClientThread/clth.pyc b/Server/ClientThread/clth.pyc deleted file mode 100644 index ec0d8ac618fc17fd7a5874ba10400602428d524d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1834 zcmcIkO>f&q5S^tyY%y|ExJ^}{JrMAPMUV(N^il+F67_5ZbbufZ41yq65oL;0xGN(8 zlvDfb@(1!m@&nTMhK^$Q>`L0v<8pRq_RZVreLe_({n)(9Gh&c^U5zCuHPrD5%+b6Fk-$pqp#oK9#GDrlLRKE z<%==H3TOpU0Z_!p9+{q?`je}PzD}^X?>>tkNPA=;yAN8gYZ>8?fQvs)IWXKL-H{t!1T?1lT(>=-l=njhj)*!^z+yGBl!>rNJLwKE(lO_#TPwk z(JTTgw-cXv8w!41;mGfacEyew?E{6fr>7> "+str(data)) - self.send_all(str(self.user)+" >> "+data) + print str(self.user) + ' >> ' + str(data) + self.send_all(str(self.user)+" >> "+data) def send_all(self,data): for client in self.listclient : if id(client) != id(self.clientsocket) : diff --git a/Server/ClientThread/clth.py~ b/Server/lib/ClientThread/clth.py~ similarity index 100% rename from Server/ClientThread/clth.py~ rename to Server/lib/ClientThread/clth.py~ diff --git a/Server/lib/__init__.py b/Server/lib/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Server/lib/server.py b/Server/lib/server.py new file mode 100644 index 0000000..0f47b7f --- /dev/null +++ b/Server/lib/server.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +# (C) coded by Tabib Ghaith + +import socket +import threading +import ClientThread.clth as cl + +#------------------------------------------------------------------------------------------------------# +class Server(object): + + def __init__(self, port=4141, user_list=[]): + self.user_list = user_list + # prepare the socket + self.port = port + self.sock = socket.socket()# standard TCP protocole + self.sock.bind(("",self.port)) + self.listclient = [] + + def start(self): + # let's begin ! + print '[.] Server Started !' + user_id = 0 + while True : + # waiting for client + self.sock.listen(10) + # accept him no password la walou (make a socket for him ) + (client, (ip,port)) =self.sock.accept() + # store the client socket so after we can closed in case of + self.listclient.append(client) + user_id = user_id + 1 + + # let the thread handel him so we can accept more + thread = cl.ClientThread(ip, port, client, self.user_list, self.listclient) + thread.start() + + def deconnectall(self): + # close all socket + for client in self.listclient : + client.shutdown(socket.SHUT_WR) + client.close() + + def release_listen(self): + # listening socket please stop + socket.socket().connect( ('127.0.0.1', self.port)) + self.deconnectall() + self.sock.close() + def stop(self): + global end + # in case button exit used + end = True + self.deconnectall() + self.release_listen() diff --git a/Server/server b/Server/server new file mode 100644 index 0000000..d4be277 --- /dev/null +++ b/Server/server @@ -0,0 +1,42 @@ +#!/usr/bin/python +# (C) coded by Tabib Ghaith + + +from lib.server import Server +import sys + +#------------------------ Help Funtion ------------------------# +def help(): + return """ + _ _ _____ _ ____ + | | | | ____| | | _ \* + | |_| | _| | | | |_) | + | _ | |___| |___| __/ + |_| |_|_____|_____|_| + """ + + +#------------------------ Main Function -----------------------# +def Main(): + if len(sys.argv) < 2: + print "python server: invalid arguments" + print "Try 'python server --help' for more information" + return 2 + elif sys.argv[1] == '--help': + print help() + return 0 + else : + try: + user_list = [] + # creating server object + server = Server(int(sys.argv[1]), user_list) + # starting server + server.start() + # stop listening and close connections1 + server.stop() + except Exception as e: + print '[!] ' + str(e) + + +if __name__ == '__main__': + Main() diff --git a/Server/server.py b/Server/server.py deleted file mode 100644 index f96d5a5..0000000 --- a/Server/server.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/python -# (C) coded by Tabib Ghaith - -import socket -import threading -import serverinterface.graphique -import ClientThread.clth -#-------------------Global Vars-----------------------------------------------------------------------# -end = False -Buffer = [] -user_list = [] - -#------------------------------------------------------------------------------------------------------# - -class ServingClient(threading.Thread): - - def __init__(self): - threading.Thread.__init__(self) - # prepare the socket - self.port = 5000 - self.sock = socket.socket()# standard TCP protocole - self.sock.bind(("",self.port)) - self.listclient = [] - - def run(self): - global end - # let's begin ! - Buffer.append("server started \n-------------------------------------------") - user_id = 0 - while True : - # waiting for client - self.sock.listen(10) - # accept him no password la walou (make a socket for him ) - (client, (ip,port)) =self.sock.accept() - # store the client socket so after we can closed in case of - self.listclient.append(client) - user_id = user_id + 1 - if end : break - # let the thread handel him so we can accept more - thread = ClientThread.clth.ClientThread(ip,port,client,Buffer,user_list,self.listclient) - thread.start() - - def deconnectall(self): - # close all socket - for client in self.listclient : - client.shutdown(socket.SHUT_WR) - client.close() - - def release_listen(self): - # listening socket please stop - socket.socket().connect( ('127.0.0.1',5000)) - self.deconnectall() - self.sock.close() - def stoping(self): - global end - # in case button exit used - end = True - self.deconnectall() - self.release_listen() - -#------------------------ the main -----------------------# -def Main(): - - - # creating the server socket thread - mainthread = ServingClient() - # creating the app - Myapp = serverinterface.graphique.app(Buffer,user_list,mainthread.stoping) - mainthread.start() - - # looping our window - Myapp.loop() - - - # do a looping (bouclage 127.0.0.1) to release the listening in case of the user press x (not exit button) - mainthread.stoping() - mainthread.join() -if __name__ == '__main__': - Main() - diff --git a/Server/serverinterface/__init__.py b/Server/serverinterface/__init__.py deleted file mode 100644 index 8d1c8b6..0000000 --- a/Server/serverinterface/__init__.py +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Server/serverinterface/__init__.pyc b/Server/serverinterface/__init__.pyc deleted file mode 100644 index d357509d071a72cde98a0b989445dbbe8e377e42..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 158 zcmZSn%*!QnDnBxr0SXv_v;zYnT=##Sh>%J6X?dwmWg+JDV@F{G{l|O}F{W z(08(QrxW|Fet)y!@;5Hugfcvm)VsVzp>`hkJIU*Td(q*HIqGBNq5%@FkcDmQ0fw;VYe2NB;x^N82JN70G`bXBFNe_aiZeSyrDR1W0W# z&1L2(Qz>P1>H8F#Dsl|ORhW88o_#9kf$aXaCcjs8G2qI1x%fJkmsABnPKlqP8F+;} zw46`LXl4v3+FVy`6g~!)7<89fjd=1eg0HAmh&8jcm9&+u{~Z3bwI3?V=w+F2j)|oe)P-NJA1zh4gBm%;DiZk#; z*GEchxB~sRFpAqC5-gf!vx+evESn{88XOc*ldJsEvTcmw9*9Fj(2nsI46@YMX^gtZ-~7qcA0b}QwDK9o}K8u#U5dAPj*sQKwS$uv+$uVXju`v3M~~w zQ*jgyxib-6!h$jW#zgnnHi||!b@Jwi`qsp*iv?W~zbyWitoz#-E3!VZb9JKYuGkIQ zc_DIP+u3#qs^C?kfLUZtKVPOq<{2ZKx7ip19PHtEJbAQ>)X3Pnst~Js~ZS1d(CU%(HH{ znW<2srOF~Ik3f$vkMZuz7qqV71Bz{KrYd+s~>!r zw2Hzz*r1hL)+!?sUd5(x-Ii8#xQ2O^xZVyu3$;(Xaqq~+&%Oa)V2HZ;5WhWqEcm=~ zlfh9pwaciR_#REZw%UK#zDifF+R^pf9n#iEG!;VmMTDxlzsdj|D>is_?os74Vr&NLK)jDn1m|A zbg0Pnqa%uvH1Scy(k||TXuA)-HD8!7&1YsKxN9B<-+PSS3c^=pb5x>ULeMy}T-2975^re+!;MnkP;M0x>?BF}h6Q7^ND zu8X4ZIbOqUkat!ocde#{4DJJrf;LW@xs@6}?+S{86TM1?+C+7>le^gB>K5`k5VHM* otUT>0W&b-mc1^EJKc>|hx2I*Kp3(4v6)|rX^>3~+H$AubKamTE(*OVf diff --git a/Server/serverinterface/graphique.py~ b/Server/serverinterface/graphique.py~ deleted file mode 100644 index 0862f0f..0000000 --- a/Server/serverinterface/graphique.py~ +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python -# (C) coded by Tabib Ghaith - -from Tkinter import * -import ttk -import threading -import time -import socket -def add_user(user_name,myapp): - myapp.liste.insert(END, user_name) - -def stop(stoping): - # Stop the mainthread - stoping() - # wait until all the threads are over max 1s - time.sleep(1) - exit(0) -def data_update(Buffer,console,user_list,liste,stoping): - # empty the buffer into the console text (refresh every 0.5ms) - if Buffer != [] : - console.config(state=NORMAL) - console.insert('end',Buffer[0]) - console.config(state=DISABLED) - del Buffer[0] - # update user list - liste.delete(0, END) - for user in user_list : - liste.insert(END, user) - console.after(500, data_update,Buffer,console,user_list,liste,stoping) -class app(object): - def __init__(self,Buffer,user_list,stoping): - # creating out main window (root) - self.root = Tk() - self.root.title('Server') - # creating the console and scrollbar - self.console = Text(self.root,width=50,height=20,wrap='word',state=DISABLED,bg="white") - self.console.grid(row = 0 , column=0,padx=1,pady=1) - self.scrollbar = ttk.Scrollbar(self.root,orient = VERTICAL ,command=self.console.yview) - self.scrollbar.grid(row = 0 , column=1,sticky ='ns') - self.console.config(yscrollcommand = self.scrollbar.set) - # user list - self.liste = Listbox(self.root,bg="white") - self.liste.grid(row = 0 , column=2,columnspan=2,sticky=W+E+N+S,) - # button start server and exit - self.button1 = ttk.Button(self.root, text ='Start Server',command=lambda: data_update(Buffer,self.console,user_list,self.liste,stoping)) - self.button1.grid(row = 1 , column=2) - self.button2 = ttk.Button(self.root, text =' Exit ',command=lambda: stop(stoping)).grid(row = 1 , column=3) - - # keep the window opened - def loop(self): - self.root.mainloop() diff --git a/Server/server~ b/Server/server~ deleted file mode 100644 index bf4e5c0..0000000 --- a/Server/server~ +++ /dev/null @@ -1,80 +0,0 @@ -#!/usr/bin/env python -# (C) coded by Tabib Ghaith - -import socket -import threading -import serverinterface.graphique -import ClientThread.clth -#-------------------Global Vars-----------------------------------------------------------------------# -end = False -Buffer = [] -user_list = [] - -#------------------------------------------------------------------------------------------------------# - -class ServingClient(threading.Thread): - - def __init__(self): - threading.Thread.__init__(self) - # prepare the socket - self.port = 5000 - self.sock = socket.socket()# standard TCP protocole - self.sock.bind(("",self.port)) - self.listclient = [] - - def run(self): - global end - # let's begin ! - Buffer.append("server started \n-------------------------------------------") - user_id = 0 - while True : - # waiting for client - self.sock.listen(10) - # accept him no password la walou (make a socket for him ) - (client, (ip,port)) =self.sock.accept() - # store the client socket so after we can closed in case of - self.listclient.append(client) - user_id = user_id + 1 - if end : break - # let the thread handel him so we can accept more - thread = ClientThread.clth.ClientThread(ip,port,client,Buffer,user_list,self.listclient) - thread.start() - - def deconnectall(self): - # close all socket - for client in self.listclient : - client.shutdown(socket.SHUT_WR) - client.close() - - def release_listen(self): - # listening socket please stop - socket.socket().connect( ('127.0.0.1',5000)) - self.deconnectall() - self.sock.close() - def stoping(self): - global end - # in case button exit used - end = True - self.deconnectall() - self.release_listen() - -#------------------------ the main -----------------------# -def Main(): - - - # creating the server socket thread - mainthread = ServingClient() - # creating the app - Myapp = serverinterface.graphique.app(Buffer,user_list,mainthread.stoping) - mainthread.start() - - # looping our window - Myapp.loop() - - - # do a looping (bouclage 127.0.0.1) to release the listening in case of the user press x (not exit button) - mainthread.stoping() - mainthread.join() -if __name__ == '__main__': - Main() -