#!/usr/bin/python2
import spread
import sys
import signal
def translate(msg):
    if msg==spread.CAUSED_BY_DISCONNECT:
        return "Disconnect"
    if msg==spread.CAUSED_BY_JOIN:
        return "Join"
    if msg==spread.CAUSED_BY_LEAVE:
        return "Leave"
    if msg==spread.CAUSED_BY_NETWORK:
        return "network"

def main():
    mb=spread.connect("4803@danlaptop")
    mb.join("walsh")
    while 1:
        x=mb.receive()
        if isinstance (x, spread.MembershipMsgType):
            print x.extra,x.members,x.group,translate(x.reason)
        else:
            print x.msg_type,x.sender,x.message,x.groups

if __name__ == "__main__":
    signal.signal (signal.SIGINT, signal.SIG_DFL)
    main ()
