Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Client/client.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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))
Expand All @@ -35,28 +35,28 @@ 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 = []
# set user name and the server ip and port
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()
Binary file removed Server/ClientThread/__init__.pyc
Binary file not shown.
Binary file removed Server/ClientThread/clth.pyc
Binary file not shown.
File renamed without changes.
19 changes: 9 additions & 10 deletions Server/ClientThread/clth.py → Server/lib/ClientThread/clth.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
#!/usr/bin/env python
# (C) coded by Tabib Ghaith
# (C) coded by Tabib Ghaith

import socket
import threading

class ClientThread(threading.Thread):
def __init__(self, ip, port, clientsocket,Buffer,user_list,listclient):
def __init__(self, ip, port, clientsocket, user_list, listclient):
threading.Thread.__init__(self)
self.ip = ip
self.port = port
self.clientsocket = clientsocket
self.Buffer = Buffer
self.listclient = listclient
# get username
# get username
self.user = self.clientsocket.recv(1024)
self.user_list = user_list
self.user_list = user_list
self.user_list.append(self.user)

def run(self):
self.Buffer.append( "\n[+] Connection from " +str(self.ip)+" : "+str(self.port))
print '[+] Connection from ' + str(self.ip) + ' : ' + str(self.port)
while True :
# recv message from user
data = ''
data = self.clientsocket.recv(1028)
# analysing data
if len(data) == 0:
self.Buffer.append( "\n[-] "+str(self.user)+"("+str(self.ip)+str(self.port)+") deconnected")
print '[-] ' + str(self.user) + '( ' + str(self.ip) + str(self.port) + ' ) deconnected'
self.listclient.remove(self.clientsocket)
self.user_list.remove(self.user)
self.clientsocket.close()
break
self.Buffer.append("\n"+str(self.user)+" >> "+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) :
Expand Down
File renamed without changes.
Empty file added Server/lib/__init__.py
Empty file.
52 changes: 52 additions & 0 deletions Server/lib/server.py
Original file line number Diff line number Diff line change
@@ -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()
42 changes: 42 additions & 0 deletions Server/server
Original file line number Diff line number Diff line change
@@ -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()
80 changes: 0 additions & 80 deletions Server/server.py

This file was deleted.

1 change: 0 additions & 1 deletion Server/serverinterface/__init__.py

This file was deleted.

Binary file removed Server/serverinterface/__init__.pyc
Binary file not shown.
50 changes: 0 additions & 50 deletions Server/serverinterface/graphique.py

This file was deleted.

Binary file removed Server/serverinterface/graphique.pyc
Binary file not shown.
Loading