Example #1
0
def main():
	global is_server
	#available_ips = network.getAvailableSubnet()
	if len(sys.argv)>=2:
		arg = sys.argv[1].lower()
		if arg=="client":
			is_server = False
	if is_server:
		serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
		host = socket.gethostname()
		serversocket.bind((network.ip("wlan0"), 1055))
		serversocket.listen(10)
		print("In Server Mode")
		while True:
			clientsocket, addr = serversocket.accept()
			print("Got a connection from {}".format(addr))
			with open("receive.txt", "wb") as f:
				while True:
					data = clientsocket.recv(1024)
					if not data:
						break
					f.write(data)
			clientsocket.close()
			print("Received Data")
	else:
		print("In client mode")
		available_ips = network.getAvailableSubnet()
		print(available_ips)
		s = socket.socket()
		s.connect((available_ips[0], 1055))
		with open("Hello.txt", "rb") as f:
			data = f.read(1024)
			s.send(data)
		s.close()
		print("Done Uploading")
Example #2
0
def update_available_ips():
	global available_ips
	available_ips = network.getAvailableSubnet()