def sv_thread_func(main_lock): def sv_written(error, dummy): try: if error == 0: tell("sent reply") else: tell("failed with code %d" % error) sv_loop.stop() except: log_exception() def sv_read(error, data, dummy): try: if error == 0: tell("got request " + data) sv_socket.write_data(data + " World!", sv_written, None) else: tell("failed with code %d" % error) except: log_exception() def sv_accepted(error, sv_socket, dummy): try: if error == 0: tell("accepted client") sv_socket.read_some(1024, sv_read, None) else: tell("failed with code %d" % error) except: log_exception() def ac_configured(error, dummy): try: if error == 0: tell("socket configured") tell("now making accept request") ac_socket.accept_client(sv_socket, sv_accepted, None) tell("did accept request") else: tell("failed with code %d" % error) except: log_exception() try: tell("(server thread)") sv_socket_serv = aosocketnativenew.AoSocketServ() sv_socket_serv.connect() tell("created socket server") ac_socket = aosocketnativenew.AoSocket() tell("created socket") ac_socket.open(sv_socket_serv) tell("initialized socket") tell("creating blank socket") sv_socket = aosocketnativenew.AoSocket() sv_socket.open(sv_socket_serv) sv_socket.blank() tell("created blank socket") tell("calling listen") ac_socket.listen_bt() tell("socket bound -- now configuring") ac_socket.config_bt(ac_configured, None) tell("did config request") except: log_exception() sv_loop = aosocketnativenew.AoLoop() sv_loop.open() sv_loop.start() sv_loop.close() sv_socket.close() ac_socket.close() sv_socket_serv.close() tell("server now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def cl_thread_func(main_lock): def cl_read(error, data, dummy): try: if error == 0: tell("read " + data) else: tell("failed with code %d" % error) cl_loop.stop() except: log_exception() def cl_written(error, dummy): try: if error == 0: tell("sent request") cl_socket.read_some(1024, cl_read, None) else: tell("failed with code %d" % error) cl_loop.stop() except: log_exception() def cl_connected(error, dummy): try: if error == 0: tell("connected to server") cl_socket.write_data("GET / HTTP/1.0\n\n", cl_written, None) else: tell("failed with code %d" % error) cl_loop.stop() except: log_exception() try: tell("(client thread)") cl_socket_serv = aosocketnativenew.AoSocketServ() cl_socket_serv.connect() tell("created socket server") cl_socket = aosocketnativenew.AoSocket() tell("created socket") cl_socket.open(cl_socket_serv) tell("initialized socket") tell("attempting connect") cl_socket.connect_bt(unicode(address), cl_connected, None) tell("connect request made") except: log_exception() cl_loop = aosocketnativenew.AoLoop() cl_loop.open() cl_loop.start() cl_loop.close() cl_socket.close() cl_socket_serv.close() tell("client now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def sv_thread_func(main_lock): def sv_written(error, dummy): try: if error == 0: tell("sent reply") else: tell("failed with code %d" % error) sv_loop.stop() except: log_exception() def sv_read(error, data, dummy): try: if error == 0: tell("got request " + data) tell("sending reply") sv_socket.sendall(data + " World!", sv_written, None) tell("reply send request made") else: tell("failed with code %d" % error) sv_loop.stop() except: log_exception() def sv_accepted(error, sv_socket, dummy): try: if error == 0: tell("accepted client, now making read request") sv_socket.recv(1024, sv_read, None) tell("did read request") else: tell("failed with code %d" % error) sv_loop.stop() except: log_exception() try: tell("(server thread)") sv_socket_serv = SymbianSocketServ() tell("created socket server") ac_socket = TcpSymbianSocket() tell("created socket") tell("creating blank socket") sv_socket = TcpSymbianSocket() sv_socket.blank(sv_socket_serv) tell("created blank socket") tell("calling listen") ac_socket.listen(sv_socket_serv, address, 5) tell("now listening -- doing an accept") ac_socket.accept(sv_socket, sv_accepted, None) tell("did accept request") except: log_exception() sv_loop = aosocketnativenew.AoLoop() sv_loop.open() sv_loop.start() sv_loop.close() sv_socket.close() ac_socket.close() sv_socket_serv.close() tell("server now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def sv_thread_func(main_lock): def sv_written(orig, evtype, evstat, payload, sv_socket): try: assert evtype == "sendall" if not evstat: tell("sent reply") else: tell("failed") raise evstat except: log_exception() sv_socket.close() sv_loop.stop() def sv_read(orig, evtype, evstat, payload, sv_socket): try: assert evtype == "recv" if not evstat: tell("got request " + payload) tell("sending reply") sv_socket.sendall(payload + " World!", sv_written, sv_socket) tell("reply send request made") else: tell("failed") raise evstat except: log_exception() sv_socket.close() cl_loop.stop() def sv_accepted(orig, evtype, evstat, sv_socket, cbparams): try: assert evtype == "accept" if not evstat: tell("accepted client, now making read request") sv_socket.recv(1024, sv_read, sv_socket) tell("did read request") else: tell("failed") raise evstat except: log_exception() cl_loop.stop() def sv_listened(orig, evtype, evstat, payload, cbparams): try: assert evtype == "listen" if not evstat: tell("now listening, next doing accept") ac_socket.accept(sv_accepted, None) tell("accept request made") else: tell("failed") raise evstat except: log_exception() cl_loop.stop() try: tell("(server thread)") sv_socket_serv = SymbianSocketServ() tell("created socket server") ac_socket = TcpSymbianAsyncSocket(sv_socket_serv) tell("created socket") tell("calling listen") ac_socket.listen(sv_listened, None, host=address[0], port=address[1]) tell("listen request made") except: log_exception() sv_loop = aosocketnativenew.AoLoop() sv_loop.open() sv_loop.start() sv_loop.close() ac_socket.close() sv_socket_serv.close() tell("server now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def cl_thread_func(main_lock): def cl_read(orig, evtype, evstat, payload, cbparams): try: assert evtype == "recv" if not evstat: tell("read " + payload) else: tell("failed") raise evstat except: log_exception() cl_loop.stop() def cl_written(orig, evtype, evstat, payload, cbparams): try: assert evtype == "sendall" if not evstat: tell("sent request") cl_socket.recv(1024, cl_read, None) else: tell("failed") raise evstat except: log_exception() cl_loop.stop() def cl_connected(orig, evtype, evstat, payload, cbparams): try: assert evtype == "connect" if not evstat: tell("connected to server") cl_socket.sendall("GET / HTTP/1.0\n\n", cl_written, None) else: tell("failed") raise evstat except: log_exception() cl_loop.stop() try: tell("(client thread)") cl_socket_serv = SymbianSocketServ() tell("created socket server") cl_socket = TcpSymbianAsyncSocket(cl_socket_serv) tell("created socket") tell("attempting connect") cl_socket.connect(cl_connected, None, host=address[0], port=address[1]) tell("connect request made") except: log_exception() cl_loop = aosocketnativenew.AoLoop() cl_loop.open() cl_loop.start() cl_loop.close() cl_socket.close() cl_socket_serv.close() tell("client now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def sv_thread_func(main_lock): def sv_written(error, dummy): try: if error == 0: tell("sent reply") else: tell("failed with code %d" % error) sv_loop.stop() except: log_exception() def sv_read(error, data, dummy): try: if error == 0: qty = len(data) tell("got request of size " + str(qty)) global amount_read amount_read += qty if amount_read < data_amount: log_heap_status("sv") sv_socket.read_some(data_amount - amount_read, sv_read, None) log_heap_status("sv") else: sv_socket.write_data("thanks", sv_written, None) else: tell("failed with code %d" % error) except: log_exception() def sv_accepted(error, sv_socket, dummy): try: if error == 0: tell("accepted client") log_heap_status("sv") sv_socket.read_some(100000, sv_read, None) log_heap_status("sv") else: tell("failed with code %d" % error) except: log_exception() try: tell("(server thread with heap %d)" % miso.heap_base_address()) log_heap_status("sv") logwrite("heap avail %d" % test_heap_avail()) log_heap_status("sv") #bigdata = gen_data(999999) sv_socket_serv = aosocketnativenew.AoSocketServ() sv_socket_serv.connect() tell("created socket server") ac_socket = aosocketnativenew.AoSocket() tell("created socket") ac_socket.set_socket_serv(sv_socket_serv) ac_socket.open_tcp() tell("initialized socket") tell("creating blank socket") sv_socket = aosocketnativenew.AoSocket() sv_socket.set_socket_serv(sv_socket_serv) sv_socket.blank() tell("created blank socket") ac_socket.listen_tcp(unicode(address[0]), address[1], 5) tell("now listening -- doing an accept") ac_socket.accept_client(sv_socket, sv_accepted, None) tell("did accept request") except: log_exception() sv_loop = aosocketnativenew.AoLoop() sv_loop.open() sv_loop.start() sv_loop.close() sv_socket.close() ac_socket.close() sv_socket_serv.close() tell("server now all done, releasing main thread") thread_finish_logging() main_lock.signal()
def cl_thread_func(main_lock): def cl_read(error, data, dummy): try: if error == 0: tell("read " + data) else: tell("failed with code %d" % error) cl_loop.stop() except: log_exception() def cl_written(error, dummy): try: if error == 0: tell("sent request") cl_socket.read_some(1024, cl_read, None) else: tell("failed with code %d" % error) except: log_exception() def cl_connected(error, dummy): try: if error == 0: tell("connected to server") log_heap_status("cl") cl_socket.write_data(gen_data(data_amount), cl_written, None) log_heap_status("cl") else: tell("failed with code %d" % error) except: log_exception() try: tell("(client thread with heap %d)" % miso.heap_base_address()) log_heap_status("cl") logwrite("heap avail %d" % test_heap_avail()) log_heap_status("cl") #bigdata = gen_data(999999) cl_socket_serv = aosocketnativenew.AoSocketServ() cl_socket_serv.connect() tell("created socket server") cl_socket = aosocketnativenew.AoSocket() tell("created socket") cl_socket.set_socket_serv(cl_socket_serv) cl_socket.open_tcp() tell("initialized socket") tell("attempting connect") cl_socket.connect_tcp(unicode(address[0]), address[1], cl_connected, None) tell("connect request made") except: log_exception() cl_loop = aosocketnativenew.AoLoop() cl_loop.open() cl_loop.start() cl_loop.close() cl_socket.close() cl_socket_serv.close() tell("client now all done, releasing main thread") thread_finish_logging() main_lock.signal()