def run_test_tcp(): print 'Starting tcp server...' rpc.MicroTCPServer(mod, ('localhost', PORT)) micro(tcp_client) allmicro_run()
def run_test_udp(): print 'Starting udp server...' rpc.MicroUDPServer(mod, ('', PORT)) micro(udp_client) allmicro_run()
def run_test_tcp(): print 'Starting tcp server...' rpc.MicroTCPServer(mod, (ip_to_str(N.net[0].ip), PORT), 'lo', N, N.net[0], Sock) micro(tcp_client) allmicro_run()
def TestMonkeyPatchUDP(address): # replace the system socket with this module def UDPServer(address): listenSocket = socket.socket(AF_INET, SOCK_DGRAM) listenSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) listenSocket.bind(address) i = 1 cnt = 0 while 1: #print "waiting for connection test", i #currentSocket, clientAddress = listenSocket.accept() #print "received connection", i, "from", clientAddress print "waiting to receive" t = listenSocket.recvfrom(256) cnt += len(t[0]) print "received", t[0], cnt if cnt == 512: break def UDPClient(address): clientSocket = socket.socket(AF_INET, SOCK_DGRAM) # clientSocket.connect(address) print "sending 512 byte packet" sentBytes = clientSocket.sendto("-"+ ("*" * 510) +"-", address) print "sent 512 byte packet", sentBytes micro(UDPServer, (address,)) micro(UDPClient, (address,)) allmicro_run()
def TestMonkeyPatchUDP(address): # replace the system socket with this module def UDPServer(address): listenSocket = socket.socket(AF_INET, SOCK_DGRAM) listenSocket.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) listenSocket.bind(address) i = 1 cnt = 0 while 1: #print "waiting for connection test", i #currentSocket, clientAddress = listenSocket.accept() #print "received connection", i, "from", clientAddress print "waiting to receive" t = listenSocket.recvfrom(256) cnt += len(t[0]) print "received", t[0], cnt if cnt == 512: break def UDPClient(address): clientSocket = socket.socket(AF_INET, SOCK_DGRAM) # clientSocket.connect(address) print "sending 512 byte packet" sentBytes = clientSocket.sendto("-" + ("*" * 510) + "-", address) print "sent 512 byte packet", sentBytes micro(UDPServer, (address, )) micro(UDPClient, (address, )) allmicro_run()
c = Channel(prefer_sender=False) crecv(c, 3) micro(xf) csend_atomic(c, 3) #print '--- Channel test 2 ---' c = Channel() def xf(): print 'xf3', 2 crecv(c, 2) micro(xf) csend(c, 2) test_sequence_II() allmicro_run() T2 = T[:] print T1 assert T1 == range(1, 9) print T2 assert T2 == range(1, 9) print "all ok"
sentBytes = clientSocket.sendto("-"+ ("*" * 510) +"-", address) print "sent 512 byte packet", sentBytes micro(UDPServer, (address,)) micro(UDPClient, (address,)) allmicro_run() if len(sys.argv) == 2: if sys.argv[1] == "client": print "client started" TestTCPClient(testAddress, socket.socket) print "client exited" elif sys.argv[1] == "slpclient": print "client started" micro(TestTCPClient, (testAddress,)) allmicro_run() print "client exited" elif sys.argv[1] == "server": print "server started" TestTCPServer(testAddress, socket.socket) print "server exited" elif sys.argv[1] == "slpserver": print "server started" micro(TestTCPServer,(testAddress,)) allmicro_run() print "server exited" else: print "Usage:", sys.argv[0], "[client|server|slpclient|slpserver]" sys.exit(1) else:
def run_test_tcp(): print "Starting tcp server..." rpc.MicroTCPServer(mod, (ip_to_str(N.net[0].ip), PORT), "lo", N, N.net[0], Sock) micro(tcp_client) allmicro_run()