forked from nzisouli/Group-Chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_chat.py
More file actions
56 lines (51 loc) · 1.86 KB
/
Copy pathapp_chat.py
File metadata and controls
56 lines (51 loc) · 1.86 KB
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
from library_client import *
def Main():
print "------------------------------------"
print "Get directory service info "
address = raw_input("Address: ")
port = int(raw_input("Port: "))
grp_setdir(address, port)
print "------------------------------------"
#print Menu
print " -----MENU---- "
print "join groupname multicast_address multicast_port username ) "
print "leave groupname"
print "send groupname your_message"
print "recv groupname"
print "------------------------------------"
print " "
while True:
command = raw_input("-> ")
command = command.split(" ")
if command[0] == "join":
if command[4] == "you":
print "give another name "
continue
check=grp_join(command[1], command[2] , int(command[3]),command[4])
if check == "Error":
print "give another name "
continue
elif command[0] == "leave":
grp_leave(command[1])
elif command[0] == "send":
message = ""
for i in range(len(command)):
if i>=2:
message = message + command[i]+" "
grp_send(command[1] , message , 1024)
elif command[0] == "recv": #app will call grp_recv multiple times utnil storage is empty
mtype = 0
while mtype != -1:
(mtype,mess) = grp_rcv(command[1],1024)
if mtype == -1:
print "No messages"
elif mtype == 0:
print "New group info :" + mess
else:
print mess
else:
print " "
print "-----------------------------------------------"
print " Please give your command again"
if __name__ == "__main__":
Main()