Download SNAP Connect Python Package Manual
Transcript
Returns the password for the specified username in the realm
realm : This server's realm. For TCP connections this will
always be snap.REALM_SNAP
username : The username specified by the remote server
"""
if username == my_user:
return my_password
def echo(obj):
"""Just a function that can be called remotely"""
print str(obj)
def main():
global comm
global my_user, my_password
usage = "usage: %prog [options] [other-node-IP-addresses]"
parser = OptionParser(usage)
parser.add_option("-d", "--deaf", action="store_true", dest="no_listener",
default=False, help="DON'T listen for incoming TCP/IP connections (default is DO
listen)")
parser.add_option("-c", "--com", dest="comport", help="open a connection on the
specified COM port (0 = COM1)")
parser.add_option("-s", "--ss200", dest="ss200", help="open a connection on the
specified SS200 device (0 = SNAPstick0)")
parser.add_option("-l", "--legacy", dest="usb", help="open a connection on the
specified USB device (0 = USB0)")
parser.add_option("-u", "--user", dest="user", default=DEFAULT_USER,
help='specify an alternative SNAP Realm user name(default is "public")')
parser.add_option("-p", "--password", dest="password",
default=DEFAULT_PASSWORD, help='specify an alternative SNAP Realm password (default
is "public")')
(options, args) = parser.parse_args()
print options
print args
funcdir = {"echo": echo}
comm = snap.Snap(funcs=funcdir)
my_user = options.user
my_password = options.password
if options.no_listener:
print "Listening for incoming TCP/IP connections has been disallowed by
user"
else:
print "Listening for incoming TCP/IP connections"
comm.accept_tcp(auth_info=my_server_auth)
if len(args) != 0:
# Establish requested outbound TCP/IP connections
for arg in args:
print "Establishing a TCP/IP link to "+arg
comm.connect_tcp(arg, auth_info=my_client_auth)
# Did the user ask us to open a normal serial port connection (COM1-COMn)?
if options.comport != None:
port = int(options.comport)
20
SNAP Connect Python Package Manual