-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
49 lines (43 loc) · 1.36 KB
/
server.py
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
import socket,pickle,_thread
grp_dic={1:[]}
serverobj=socket.socket()
serverobj.bind(("127.0.0.1",3000))
serverobj.listen(50)
dic_track=2
def message_receive(s,gid):
global grp_dic
print("message_receive called %d" %gid)
print(grp_dic[1])
while True:
msg=pickle.loads(s.recv(1024))
print(msg+" %d"%gid)
print("Message receipients" )
print(grp_dic[gid])
for i in grp_dic[gid]:
if not i._closed:
print(i._closed)
print("Pushing")
i.send(pickle.dumps(msg))
else:
print(i._closed)
def connection_accept():
print("2")
global grp_dic,dic_track,serverobj
while True:
print("Waiting for connection")
connection, address = serverobj.accept()
print(" connected %d"%len(grp_dic))
for i in range(1,len(grp_dic)+1):
print(" %d i in connection accept" %i)
if len(grp_dic[i])<5 :
grp_dic[i].append(connection)
print("appended")
break
else:
grp_dic[dic_track]=[connection]
dic_track+=1
print("appeded2")
_thread.start_new_thread(message_receive, (connection,dic_track-1))
print("1")
_thread.start_new_thread(connection_accept(),())
print("hai")