def accept_loop(server):
    tell("thread %d in accept_loop" % thread.get_ident())
    try:
        while True:
            endpoint = server.accept()
            stream = BufferedStream(SafeSocket(endpoint))
            start_thread(echo_loop, args=(stream, ))
    except ServerTerminated:
        tell("Accept loop exited normally.")
    except:
        tell("Accept loop exited abnormally.")
    tell("releasing main thread")
    thread_finish_logging()
    mn_wait_acc.release()
def get_device_list():
    list = []
    tid = start_thread(target=cl_thread_func,
                       name="worker-thread",
                       args=(list, ))
    thread.ao_waittid(tid)
    return list
    def create_internal_thread(self):
        """
        This method creates and starts the internal thread that owns
        all the sockets, storing a reference to it in the internal
        ``thread`` property.
        """
        # Create the Symbian-specific instance of this.
        self.itc = SymbianItc()

        # Now create and start the thread.
        # Do not forget to store the thread ID.
        if logging_enabled():
            logwrite("starting internal thread")
        self.thread = None
        self.thread = start_thread(target=self.__loop,
                                   name="socket-owner-thread-%d" % hash(self),
                                   args=())










tell("(main thread)")

cl_blocker = e32.Ao_lock()
cl_thread = start_thread(
    target = cl_thread_func,
    name = "client-thread",
    args = (cl_blocker,))
tell("started client thread")

tell("waiting for client")
cl_blocker.wait()

tell("all done")

# --------------------------------------------------------------------

appuifw.app.title = old_title
thread_finish_logging()
finish_logging()
Esempio n. 5
0
    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()


tell("(main thread)")

sv_blocker = e32.Ao_lock()
sv_thread = start_thread(target=sv_thread_func,
                         name="server-thread",
                         args=(sv_blocker, ))
tell("started server thread")
time.sleep(3)

tell("waiting for server")
sv_blocker.wait()

tell("all done")

# --------------------------------------------------------------------

appuifw.app.title = old_title
thread_finish_logging()
finish_logging()
            start_thread(echo_loop, args=(stream, ))
    except ServerTerminated:
        tell("Accept loop exited normally.")
    except:
        tell("Accept loop exited abnormally.")
    tell("releasing main thread")
    thread_finish_logging()
    mn_wait_acc.release()


address = ("tcp", "localhost", 12345)

server = listen(address)
mn_wait_acc = thread.allocate_lock()
mn_wait_acc.acquire()
start_thread(accept_loop, args=(server, ))

client = connect(address)
stream = BufferedStream(SafeSocket(client))

stream.write("Hello world!\n")
stream.flush()
print stream.readline(),

stream.write("This is a")
stream.write(" test.\n")
stream.flush()
print stream.readline(),

stream.close()
assert not stream.readline()
Esempio n. 7
0









tell("(main thread)")

if not client_mode:
    sv_blocker = e32.Ao_lock()
    sv_thread = start_thread(
        target = sv_thread_func,
        name = "server-thread",
        args = (sv_blocker,))
    tell("started server thread")
    time.sleep(3)

cl_blocker = e32.Ao_lock()
cl_thread = start_thread(
    target = cl_thread_func,
    name = "client-thread",
    args = (cl_blocker,))
tell("started client thread")

if not client_mode:
    tell("waiting for server")
    sv_blocker.wait()
tell("waiting for client")
        logwrite("server all done")
        thread_finish_logging()
    except:
        log_exception()
    mutex.release()


try:
    tell("(main thread)")
    manager = lookup_manager("ao_tcp")
    tell("fetched manager")

    blocker = thread.allocate_lock()
    blocker.acquire()
    server_thread = start_thread(target=server_loop,
                                 name="server-thread",
                                 args=(manager, blocker))
    tell("started thread")
    time.sleep(3)

    tell("attempting connect")
    cl_socket = manager.connect(address)
    tell("connected client socket")
    time.sleep(1)
    cl_socket.sendall("Hello")
    tell("did a send")
    data = cl_socket.recv(1024)
    tell("received response (logged)")
    logwrite(data)
    time.sleep(1)
    cl_socket.close()
Esempio n. 9
0
            i = appuifw.popup_menu(peers, u"Select peer:")
            tell("selected " + str(i))
            if i is not None:
                address = peers[i]

        if (not amClient) or address:
            from aosocket.symbian.bt import BtManager
            _manager = BtManager(400)
            try:
                tell("(main thread)")

                if amClient:
                    target = cl_thread_func
                else:
                    target = sv_thread_func

                tid = start_thread(target=target,
                                   name="worker-thread",
                                   args=())
                tell("started thread")

                tell("waiting for worker thread to finish")
                thread.ao_waittid(tid)

                tell("all done")
            finally:
                _manager.close()
except:
    log_exception()
    appuifw.note(u"Fatal error.", "error")