def main():
    parser = argparse.ArgumentParser(description='Python broadcast chat')
    parser.add_argument("nickname", help="User nickname in chat")
    parser.add_argument("interface", help="Network interface")
    args = parser.parse_args()
    ifname = args.interface
    interface = Interface()
    host_addr = interface.getAddr(ifname)
    #net_addr = interface.getNetmask(ifname)
    #bcast_addr = interface.getBroadcast(ifname)
    #netmask = interface.getNetmask(ifname)
    print "******Interface params******"
    print "host_addr ", host_addr
    #print "netmask   ", netmask
    #print "bcast_addr", bcast_addr
    chat = MulticastChat(args.nickname, host_addr)
    thread = ChatThread(chat)
    thread.start()
    try:
        while True:
            print_protompt()
            command = raw_input()
            command_list = command.split()
            if not command:
	            continue
            elif command in ["!help", "!h"]:
                print """!help - this help message
!list - list chat users
!list - list chat user in room number
!quit - quit a chat
!j <number> - join room number
!r - list your rooms
!e <number> - exit room number
!send <message> (!s <message>)- send a message
!sendroom <room_number> message (!sr <room_number> message) - send message for members of room_number
!am print your nick"""
            elif command in ["!quit", "!q"]:
                break
            elif command in ["!list", "!l"]:
                print "User lists:"
                chat.list()
            elif command in ["!am"]:
		print "Your nick is %s" % chat.get_nick()
            elif (len(command_list) == 2) and command_list[0] in ["!list", "!l"]:
                try:
                    room = int(command_list[1])
                except ValueError, e:
                    print "Invalid room value"
                    continue
                print "Room %d users list" % room
                chat.list(room)
            elif command in ["!r"]:
                chat.list_rooms()
            elif (len(command_list) == 2) and (command_list[0] in ['!j']):
                try:
                    room = int(command_list[1])
                except ValueError, e:
                    print "Invalid room number"
                    continue
def main():
    parser = argparse.ArgumentParser(description='Python broadcast chat')
    parser.add_argument("nickname", help="User nickname in chat")
    parser.add_argument("interface", help="Network interface")
    args = parser.parse_args()
    ifname = args.interface
    interface = Interface()
    host_addr = interface.getAddr(ifname)
    net_addr = interface.getNetmask(ifname)
    bcast_addr = interface.getBroadcast(ifname)
    netmask = interface.getNetmask(ifname)
    print "******Interface params******"
    print "host_addr ", host_addr
    print "netmask   ", netmask
    print "bcast_addr", bcast_addr
    chat = Chat(args.nickname, host_addr, bcast_addr)
    thread = ChatThread(chat)
    thread.start()
    try:
        while True:
            print_protompt()
            command = raw_input()
            if command in ["!help", "!h"]:
                print """!help - this help message
!list - list chat users
!quit - quit a chat
!send <message> - send a message"""
            elif command in ["!quit", "!q"]:
                break
            elif command in ["!list", "!l"]:
                print "User lists:"
                chat.list()
            elif (command[:5] == ["!send"]) or (command[:2] == "!s"):
                if command.startswith("!send "):
                    message = command[6:]
                elif command.startswith("!s"):
                    message = command[3:]
                else:
                    print "Command error"
                    continue
                chat.send(message)
            elif not command:
	      continue
            else:
                print "Invalid command. type '!help' or '!h' for help"
    except KeyboardInterrupt:
        print "\nGood bye!"
    finally:
        thread.shutdown()
        thread.join()
        chat.close()
예제 #3
0
파일: chat2.py 프로젝트: Triol19/BSUIR-Labs
def main():
    parser = argparse.ArgumentParser(description='Python multicast chat')
    parser.add_argument("nickname", help="User nickname in chat")
    parser.add_argument("interface", help="Network interface")
    args = parser.parse_args()
    ifname = args.interface
    interface = Interface()
    host_addr = interface.getAddr(ifname)
    #net_addr = interface.getNetmask(ifname)
    #bcast_addr = interface.getBroadcast(ifname)
    #netmask = interface.getNetmask(ifname)
    print "******Interface params******"
    print "host_addr ", host_addr
    #print "netmask   ", netmask
    #print "bcast_addr", bcast_addr
    chat = MulticastChat(args.nickname, host_addr)
    thread = ChatThread(chat)
    thread.start()
    try:
        while True:
            print_protompt()
            command = raw_input()
            command_list = command.split()
            if not command:
	            continue
            elif command in ["!help", "!h"]:
                print_help()
            elif command in ["!quit", "!q"]:
                break
            elif command in ["!list", "!l"]:
                print "User lists:"
                chat.list()
            elif command in ["!am"]:
                print "Your nick is {}".format(chat.get_nick())
            elif (len(command_list) == 2) and command_list[0] in ["!list", "!l"]:
                try:
                    room = int(command_list[1])
                except ValueError, e:
                    print "Invalid room value"
                    continue
                print "Room {} users list".format(room)
                chat.list(room)
            elif command in ["!r"]:
                chat.list_rooms()
            elif (len(command_list) == 2) and (command_list[0] in ['!j']):
                try:
                    room = int(command_list[1])
                except ValueError, e:
                    print "Invalid room number"
                    continue