当前位置: 首页>>代码示例>>Python>>正文


Python MainWindow.getline方法代码示例

本文整理汇总了Python中gui.MainWindow.getline方法的典型用法代码示例。如果您正苦于以下问题:Python MainWindow.getline方法的具体用法?Python MainWindow.getline怎么用?Python MainWindow.getline使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gui.MainWindow的用法示例。


在下文中一共展示了MainWindow.getline方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: loop

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def loop(HOST, PORT, CERT):

	server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	server.connect((HOST, PORT))

	buffer = []
	disconnected = False

	# The following code explains how to use the GUI.
	w = MainWindow()
	# update() returns false when the user quits or presses escape.
	while w.update():

		if disconnected:
			continue

		try:
			rready, wready, xready = select.select([server], [server], [server])

			# ready to receive
			if server in rready:
				data = server.recv(1024)
				if not data:
					server.close()
					w.writeln("<server disconnected>")
					disconnected = True
					continue

				# print message
				w.writeln(data.rstrip())

			# ready to send
			if server in wready:
				if len(buffer) > 0:
					server.sendall(buffer.pop())

			# error
			if server in xready:
				server.close()
				sys.exit(1)

			# if the user entered a line getline() returns a string.
			line = w.getline()
			if line:
				buffer.append(line)
				w.writeln("> " + line)

		# close server on SIGINT
		except (KeyboardInterrupt, SystemExit):
			print "\nDisconnecting..."
			server.close()
			print "Cheers!"
			sys.exit(0)
开发者ID:Lapixx,项目名称:CS-UvA-NS2B,代码行数:55,代码来源:lab2b_client_Kersjes_T.py

示例2: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(mcast_addr,
	sensor_pos, sensor_range, sensor_val,
	grid_size, ping_period):
	"""
	mcast_addr: udp multicast (ip, port) tuple.
	sensor_pos: (x,y) sensor position tuple.
	sensor_range: range of the sensor ping (radius).
	sensor_val: sensor value.
	grid_size: length of the  of the grid (which is always square).
	ping_period: time in seconds between multicast pings.
	"""
	
	# -- make the gui --
	window = MainWindow()
	
	# -- make the node --
	node = Node(mcast_addr, sensor_pos,sensor_range, sensor_val, window)
	
	start_time = time.time()


	# -- This is the event loop. --
	while window.update():
		node.updateSelect()
		
		# Auto ping
		if (time.time() - start_time) > ping_period:
			node.sendPing()
			start_time = time.time()


		# Check for new messages
		for c in node.readable:
			# Receive message from server and write to the window
			data = c.recvfrom(1024)
			parseData(data, node)
		
		# Check if something was entered in the GUI, parse the input and execute the corresponding command
		line = window.getline()
		if line:
			parseInput(line, node)
	
		# # Prevent busy looping
		time.sleep(0.1)
开发者ID:JeroenVranken,项目名称:lab5,代码行数:46,代码来源:mainFunction.py

示例3: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(mcast_addr,
	sensor_pos, sensor_range, sensor_val,
	grid_size, ping_period):
	"""
	mcast_addr: udp multicast (ip, port) tuple.
	sensor_pos: (x,y) sensor position tuple.
	sensor_range: range of the sensor ping (radius).
	sensor_val: sensor value.
	grid_size: length of the  of the grid (which is always square).
	ping_period: time in seconds between multicast pings.
	"""
	node = nodeContainer()
	# -- make sockets
	node.init(mcast_addr)
	# -- set node values
	node.position = sensor_pos
	node.range = sensor_range
	node.value = sensor_val
	node.pingTime = ping_period
	# -- create gui
	window = MainWindow()
	node.setWindow(window)
	# -- Command/message parser
	parser = msgParser(node)
	# -- Both peer and Mcast connections
	conns = node.getConnections()

	# -- This is the event loop
	while window.update():
		inputReady, outputReady, errorReady = \
			select.select(conns, [], [], 0.025)
		# Is it ping time already
		node.autoPing()

		# Network message
		for s in inputReady:
			parser.parseSensorMessage(s)

		# Gui message
		line = window.getline()
		if line:
			parser.parseLine(line);
开发者ID:blackshadev,项目名称:HWlinkTV,代码行数:44,代码来源:lab5-yourname.py

示例4: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(mcast_addr,
	sensor_pos, sensor_range, sensor_val,
	grid_size, ping_period):
	"""
	mcast_addr: udp multicast (ip, port) tuple.
	sensor_pos: (x,y) sensor position tuple.
	sensor_range: range of the sensor ping (radius).
	sensor_val: sensor value.
	grid_size: length of the  of the grid (which is always square).
	ping_period: time in seconds between multicast pings.
	"""
	# -- Create the multicast listener socket. --
	mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	# Sets the socket address as reusable so you can run multiple instances
	# of the program on the same machine at the same time.
	mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
	# Subscribe the socket to multicast messages from the given address.
	mreq = struct.pack('4sl', inet_aton(mcast_addr[0]), INADDR_ANY)
	mcast.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
	mcast.bind(mcast_addr)

	# -- Create the peer-to-peer socket. --
	peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	# Set the socket multicast TTL so it can send multicast messages.
	peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 5)
	# Bind the socket to a random port.
	if sys.platform == 'win32': # windows special case
		peer.bind( ('localhost', INADDR_ANY) )
	else: # should work for everything else
		peer.bind( ('', INADDR_ANY) )

	# -- make the gui --
	window = MainWindow()
	window.writeln("My address is %s:%s" % peer.getsockname())
	window.writeln("My position is (%s, %s)" % sensor_pos)
	window.writeln("My sensor value is %s" % sensor_val)
	
	# Periodic pinging. A value of -1 causes an immediate ping event.
	# When entering the group, a first ping is sent.
	lastpingtime = -1
	
	# The set of neighbours; (position, address).
	neighbours = set()
	
	# The echo sequence number.
	echoseq = -1;
	
	# The dictionary of fathers of currently active echo's; (position, address).
	father = {}
	# The dictionary of sets of pending neighbours of currently active echo's.
	echo = {}
	# The dictionary of operations of currently active echo's.
	echoop = {}
	# The dictionary of lists of loads of currently active echo's.
	echoload = {}

	# -- This is the event loop. --
	while window.update():
		line = window.getline()
		
		# Our event loop will consist of 5 steps.
		# 1: Interpret the command line input (if any).
		# 2: If a ping event should occur, ping.
		# 3: If an echo event should occur, echo.
		# 4: If one or more messages are received, handle them.
		# 5: If echo's have finished, show or forward their results.
		
		# The operation of a new echo. If the value is nonnegative, an echo occurs.
		newechoop = -1
		
		if (line):
			#debug: window.writeln("> " + line)
			
			#switch line
			if (line == "ping"):
				# Cause a ping event immediately.
				lastpingtime = -1
			elif (line == "list"):
				window.writeln("Neighbours:")
				for (npos, naddr) in neighbours:
					window.writeln("\t- neighbour at " + str(npos) + " from " + str(addr))
				#end for neighbours
				window.writeln("\t(end of list)")
			elif (line == "move"):
				sensor_pos = random_position(grid_size)
				window.writeln("My new position is (%s, %s)" % sensor_pos)
			elif (line == "value"):
				sensor_val = randint(0, 100)
				window.writeln("My sensor value is %s" % sensor_val)
			elif (line == "echo"):
				newechoop = OP_NOOP
			elif (line == "size"):
				newechoop = OP_SIZE
			elif (line == "sum"):
				newechoop = OP_SUM
			elif (line == "max"):
				newechoop = OP_MAX
			elif (line == "min"):
				newechoop = OP_MIN
			else:
#.........这里部分代码省略.........
开发者ID:SLiV9,项目名称:ns-lab5,代码行数:103,代码来源:lab5-8.py

示例5: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]

#.........这里部分代码省略.........
    window.writeln("sensor value = " + str(value))

    # Send ping to all other users and start clock
    send_ping(peer)

    start = time.time()
    
    # Input for select
    input = [mcast, peer]

    peer.setblocking(0)
    mcast.setblocking(0)

    while window.update():
        # In case 5 seconds have passed resend ping message
        if ((time.time() - start) > PING_PERIOD):
            neighbors = []
            send_ping(peer)
            start = time.time()
        
        # Read input from mcast and peer
        try: 
            message, address = mcast.recvfrom(1024)
            handle_message(peer, mcast, message, address)
        except error:
            pass
        try: 
            message, address  = peer.recvfrom(1024)
            handle_message(peer, mcast, message, address)
        except error:
            pass
        
        #See if there was GUI input
        command = window.getline()

        # Send a ping to the rest
        if(command == "ping"):
            neighbors = []
            window.writeln("Sending ping over multicast...")
            send_ping(peer)

        # Show the list of neighbors
        elif(command == "list"):
            window.writeln("List of neighbors <(x,y), ip:port>:")
            if neighbors == []:
                window.writeln("No neighbors found")
            for i in neighbors:
                window.writeln(str(i[0]) + ", " + str(i[1][0]) + ":" + str(i[1][1]))

        # Move to a new random position
        elif(command == "move"):
            x = random.randint(0, 99)
            y = random.randint(0, 99)
            window.writeln("New position = " + str((x,y)))

        # Get a random new sensor value 
        elif(command == "value"):
            value = random.randint(0, 10)
            window.writeln("New sensor value = " + str((x,y)))

		# Initiate wave
        elif(command == "wave"):
            size_wave = False
            sum_wave = False
            waveSeqNr += 1
            window.writeln("Starting wave...")
开发者ID:Braamling,项目名称:Netwerken-en-systeembeveiliging,代码行数:70,代码来源:lab8-skeleton2.py

示例6: MainWindow

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
    """
    sock = None
    try:
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        sock.connect((host, port))

    except socket.error, e:
        print 'Could not connect to server @%d' % port
        sys.exit(1) 


    # The following code explains how to use the GUI.
    w = MainWindow()
    # update() returns false when the user quits or presses escape.
    while w.update():
        line = w.getline()
        if line:
            while True:
                sock.send(line)    

        inputready, outputready, exceptrdy = select.select([sock], [],[], 0.3)
        for i in inputready:
            if i == sock:
                data = sock.recv(1024)
                if not data:
                    print 'Shutting down.'
                    w.quit()
                else:
                    w.writeln(data)
            
开发者ID:Snuggert,项目名称:informatica,代码行数:31,代码来源:lab3client-AbeWiersma.py

示例7: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(argv):
    """
    Program entry point.
    """

    #last received echo message
    global echoMsg
    echoMsg = (0, 0)

    global neighbor_replies
    neighbor_replies = []

    #IP and port of father 
    global father
    father = (-1, -1)

    global waveSeqNr
    waveSeqNr = 0
    # Set some of the global variables
    global neighbors
    neighbors = []
    # TODO: Make global and no duplicate values between nodes
    global x 
    x = random.randint(0, 10)    
    global y
    y = random.randint(0, 10)

    global value
    value = random.randint(0, 259898)

    ## Create the multicast listener socket and suscribe to multicast.
    mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
    socket_subscribe_mcast(mcast, MCAST_GRP)
    # Bind it to the multicast address.
    # NOTE: You may have to bind to localhost or '' instead of MCAST_GRP
    # depending on your operating system.
    # ALSO: In the lab room change the port to MCAST_PORT + group number
    # so that messages rom different groups do not interfere.
    # When you hand in your code in it must listen on (MCAST_GRP, MCAST_PORT).

    # Make resuable
    mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    mcast.bind((MCAST_GRP, MCAST_PORT))

    ## Create the peer-to-peer socket.
    peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
    # Set the socket multicast TTL so it can send multicast messages.
    peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 2)


    # Bind the socket to a random port.
    peer.bind(('', INADDR_ANY))

    ## This is the event loop.
    window = MainWindow()

    print (x,y)

    # Show information of newly connected node TODO: Display Local IP
    ip_port = "IP:Port = " + str(MCAST_GRP) + ":" + str(INADDR_ANY)
    window.writeln(ip_port)

    window.writeln("position = (" + str(x) + ", " + str(y) + ")")
    window.writeln("sensor value = " + str(value))

    # Send ping to all other users and start clock
    send_ping(peer)

    start = time.time()
    
    # Input for select
    input = [mcast, peer]

    peer.setblocking(0)
    mcast.setblocking(0)

    while window.update():
        # In case 5 seconds have passed resend ping message
        if ((time.time() - start) > PING_PERIOD):
            neighbors = []
            send_ping(peer)
            start = time.time()
        
        # Read input from mcast and peer
        try: 
            message, address = mcast.recvfrom(1024)
            handle_message(peer, mcast, message, address)
        except error:
            pass
        try: 
            message, address  = peer.recvfrom(1024)
            print message_decode(message)
            handle_message(peer, mcast, message, address)
        except error:
            pass
        
        #See if there was GUI input
        command = window.getline()
        # Send a ping to the rest
        if(command == "ping"):
#.........这里部分代码省略.........
开发者ID:Braamling,项目名称:Netwerken-en-systeembeveiliging,代码行数:103,代码来源:lab8-skeleton_BACKUO.py

示例8: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(argv):
	"""
	Program entry point.
	"""
	## Create the multicast listener socket and suscribe to multicast.
	mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	socket_subscribe_mcast(mcast, MCAST_GRP)
	# Set socket as reusable.
	mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
	# Bind it to the multicast address.
	# NOTE: You may have to bind to localhost or '' instead of MCAST_GRP
	# depending on your operating system.
	# ALSO: In the lab room change the port to MCAST_PORT + group number
	# so that messages from different groups do not interfere.
	# When you hand in your code in it must listen on (MCAST_GRP, MCAST_PORT).
	mcast.bind((MCAST_GRP, MCAST_PORT))

	## Create the peer-to-peer socket.
	peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	# Set the socket multicast TTL so it can send multicast messages.
	peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 2)
	# Bind the socket to a random port.
	peer.bind(('', INADDR_ANY))

	## This is the event loop.
	window = MainWindow()

#---------- BEGIN EIGEN CODE ------------#
	
	# Set up most of the globals
	setup_globals()

	global portnumber, father
	# Get socket information
	father = peer.getsockname()
	_,portnumber = father
	#address, portnumber = peer.getsockname()
	
	global a, b
	a = 1
	b = 2

	# Set blocking to zero
	peer.setblocking(0)
	mcast.setblocking(0)

	# Set up position node
	move()
	
	#TODO FOR TESTING ONLY!!
	if(len(argv) == 3):
		global nx,ny
		nx = int(argv[1])
		ny = int(argv[2])
		global node_location
		node_location = (nx,ny)


	# Print out information in gui
	window.write("INFORMATION\nIP:port:\t" + str(portnumber) + "\nPosition:\t" + str(node_location) + "\nSensor Value:\t" + str(sensorvalue) + "\n")

	# Send multicast PING
	send_ping(peer)
	
	# Set time	
	pingtime = time.time()



	while window.update():
		# Resend PING if time > 5s, reset
		if(time.time() - PING_PERIOD > pingtime):
			del neighbors[:] # Empty neighbors list
			send_ping(peer)
			pingtime = time.time()
			#window.writeln("------------------ reset ---------------------")
		
		# Check for receiving on multicast	
		check_multicast(mcast,peer)

		# Check for receiving on peer
		check_socket_recv(peer, window)

		# Get commands input
		command = window.getline()
		test = command.split(" ")
		if (command == "ping"):
			window.writeln("> Command entered: " + command)
			window.writeln("Sending ping over multicast...")
			send_ping(peer)

		elif (command == "list"):
			window.writeln("> Command entered: " + command)
			list(window)

		elif (command == "move"):
			window.writeln("> Command entered: " + command)
			move()
			window.writeln("New location:" + str(node_location))
		#TODO: For testing only
#.........这里部分代码省略.........
开发者ID:sagieske,项目名称:NS_lab8,代码行数:103,代码来源:lab8-skeleton2.py

示例9: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(argv):
    """
    Program entry point.
    """
    ## Create the multicast listener socket and suscribe to multicast.
    global mcast
    global peer
    mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
    socket_subscribe_mcast(mcast, MCAST_GRP)
    # Set socket as reusable.
    mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
    # Bind it to the multicast address.
    # NOTE: You may have to bind to localhost or '' instead of MCAST_GRP
    # depending on your operating system.
    # ALSO: In the lab room change the port to MCAST_PORT + group number
    # so that messages from different groups do not interfere.
    # When you hand in your code in it must listen on (MCAST_GRP, MCAST_PORT).
    mcast.bind((MCAST_GRP, MCAST_PORT))
    mcast.setblocking(0)
    ## Create the peer-to-peer socket.
    peer = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
    # Set the socket multicast TTL so it can send multicast messages.
    peer.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 2)
    # Bind the socket to a random port.
    peer.bind(('', INADDR_ANY))
    peer.setblocking(0)
    ## This is the event loop.
    global window
    window = MainWindow()
    start = time.time()
    global x
    x = random.randrange(0, GRID_SIZE)
    global y
    y = random.randrange(0, GRID_SIZE)
    global value
    value = random.randrange(0, 10000)
    global nodes
    nodes = []
    global knownWaves
    knownWaves = []
    global father
    father = []
    global receivedEchoReps
    receivedEchoReps = []
    global recPayload
    recPayload = []
    global types
    types = []
    waves = 0
    getip = socket(AF_INET, SOCK_DGRAM)
    getip.connect(("www.davidvanerkelens.nl", 80))
    ip = getip.getsockname()[0]
    port = getip.getsockname()[1]
    getip.close()
    window.writeln("Position: " + str(x) + ":" + str(y))
    window.writeln("Sensor value: " + str(value))
    window.writeln("Location: " + str(ip) + ":" + str(port))
    enc_msg = message_encode(MSG_PING, 0, (x, y), (0, 0))
    peer.sendto(enc_msg, (MCAST_GRP, MCAST_PORT))
    while window.update():
        if(time.time() - start > PING_PERIOD):
            start = time.time()
            enc_msg = message_encode(MSG_PING, 0, (x, y), (0, 0))
            peer.sendto(enc_msg, (MCAST_GRP, MCAST_PORT))
            nodes = []
        try:
            message, address = mcast.recvfrom(2048)
            process_msg(message, address, peer, mcast)
        except:
            pass
        try:
            message, address = peer.recvfrom(2048)
            process_msg(message, address, peer, mcast)
        except:
            pass
        try:
            line = window.getline()
        except:
            pass
        if(line):
            if(line == "ping"):
                window.writeln("We'll be pinging now.")
                nodes = []
                start = time.time()
                enc_msg = message_encode(MSG_PING, 0, (x, y), (0, 0))
                peer.sendto(enc_msg, (MCAST_GRP, MCAST_PORT))
            elif(line == "list"):
                window.writeln("List of neighbors:")
                if(nodes == []):
                    window.writeln("No neighbors found.")
                else:
                    for n in nodes:
                        window.writeln(str(n[1]) + " @ " + str(n[0]))
            elif(line == "move"):
                x = random.randrange(0, GRID_SIZE)
                y = random.randrange(0, GRID_SIZE)
                window.writeln("New location of sensor: " + str(x) + ":" + str(y))
            elif(line == "echo"):
                if(nodes == []):
                    window.writeln("No neighbors, echo will be aborted.")
#.........这里部分代码省略.........
开发者ID:DavidvanErkelens,项目名称:Networking,代码行数:103,代码来源:lab8.py

示例10: main

# 需要导入模块: from gui import MainWindow [as 别名]
# 或者: from gui.MainWindow import getline [as 别名]
def main(mcast_addr, sensor_pos, sensor_range, sensor_val, grid_size, ping_period):
	"""
	mcast_addr: udp multicast (ip, port) tuple.
	sensor_pos: (x,y) sensor position tuple.
	sensor_range: range of the sensor ping (radius).
	sensor_val: sensor value.
	grid_size: length of the  of the grid (which is always square).
	ping_period: time in seconds between multicast pings.
	"""
	global sequence_number
	sequence_number = 0
	global echo_message
	echo_message = (-1,-1)
	global echo_father
	echo_father = (0,0)
	global size
	size = 0
	global neighbor_list
	neighbor_list = []
	global neighbor_replies
	neighbor_replies = []
	global message_list
	message_list = []
	global value
	value = sensor_val
	global x
	global y
	(x,y) = sensor_pos

	# -- Create the multicast listener socket. --
	mcast = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	# Sets the socket address as reusable so you can run multiple instances
	# of the program on the same machine at the same time.
	mcast.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
	# Subscribe the socket to multicast messages from the given address.
	mreq = struct.pack('4sl', inet_aton(mcast_addr[0]), INADDR_ANY)
	mcast.setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, mreq)
	mcast.bind(mcast_addr)

	# -- Create the sock-to-sock socket. --
	sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
	# Set the socket multicast TTL so it can send multicast messages.
	sock.setsockopt(IPPROTO_IP, IP_MULTICAST_TTL, 5)
	# Bind the socket to a random port.
	if sys.platform == 'win32': # windows special case
		sock.bind( ('localhost', INADDR_ANY) )
	else: # should work for everything else
		sock.bind( ('', INADDR_ANY) )

	# -- make the gui --
	global window
	window = MainWindow()
	window.writeln( 'my address is %s:%s' % sock.getsockname() )
	window.writeln( 'my position is (%s, %s)' % sensor_pos )
	window.writeln( 'my sensor value is %s' % sensor_val )

	# Send ping to all other users and start clock
	send_ping(sock, sensor_pos)
	start = time.time()

	# For select
	sockets = [mcast, sock]

	# -- This is the event loop. --
	while window.update():
	# Resend every x seconds (either default is set by commandline)
		if ((time.time() - start) > ping_period):
			neighbor_list = []
			send_ping(sock, (x,y))
			start = time.time()
		
		# Read the imputs (both socket & mcast)
		read, write, error = select.select(sockets,[],[],0)
		for s in read:
			message, address = s.recvfrom(1024)
			handle_message(sock, mcast, message, address, sensor_range)
		line = window.getline()
	# Send unicast Ping
		if line == 'ping':
			window.writeln("Sending ping over multicast %s:%s" % (mcast_addr[0], mcast_addr[1]))
			neighbor_list = []
			send_ping(sock, (x,y))
	# Print all neighbors
		elif line == 'list':
			if neighbor_list == []:
				window.writeln("No neighbors")
			for neighbor in neighbor_list:
				window.writeln("%s:%s" % (neighbor[0],neighbor[1]))
	# Print Position
		elif line == 'position':
			window.writeln("(%s,%s)" % (x , y))
	# Send echo
		elif line == 'echo':
			sequence_number += 1
			window.writeln("Sending echo...")
			encoded_message = message_encode(MSG_ECHO, sequence_number, (x,y), (-1, -1), OP_NOOP, 0) 
			for i in neighbor_list:
				sock.sendto(encoded_message, i[1])
	# Send echo with operation
		elif line == 'size':
#.........这里部分代码省略.........
开发者ID:vdweegen,项目名称:UvA-Networks_and_System_Security,代码行数:103,代码来源:lab5-van_der_Weegen-Yerlibucak.py


注:本文中的gui.MainWindow.getline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。