Commit cb7666b0 authored by Philipp Auersperg's avatar Philipp Auersperg

...

parent bfc1a5cc
......@@ -51,14 +51,15 @@ class MainActivity : AppCompatActivity() {
val klass="org.bd.servicetest.ServiceTestserv"
// val intent= Intent(".MainActivity")
// val intent= Intent("org.kivy.android.PythonActivity")
// .also {intent.setPackage("org.bd.servicetest")}
val intent=Intent("org.bd.servicetest.android.intent.action.MAIN")
// val intent= Intent("org.bd.action.VIEW")
// .also {it.setPackage("org.bd")}
// val intent = Intent("org.bd.action.VIEW")
val intent = Intent("org.bd.servicetest.MAIN")
// val intent = Intent("org.bd.servicetest.MAIN")
// intent.component = ComponentName("org.bd.servicetest", "./PythonActivity")
// intent.component = ComponentName("org.bd", "./MainActivity")
......
......@@ -12,6 +12,10 @@ starting app via logcat works now
$ am start org.bd.servicetest/org.kivy.android.PythonActivity
or start the service (unfrtunately with error):
$ adb shell am startservice -n org.bd.servicetest/org.bd.servicetest.ServiceTestserv
but still searching how to start it from an android app
resources in the net:
......
......@@ -2,6 +2,7 @@ from kivy.app import App
from kivy import platform
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.clock import Clock
import logging
from kivy.logger import Logger
......@@ -35,10 +36,15 @@ Builder.load_string("""
class MainWindow(BoxLayout):
""""""
def __init__(self, **kw):
super().__init__(**kw)
Clock.schedule_once(self.start_service)
def test(self):
Logger.info("pressed")
def start_service(self):
def start_service(self, *a):
print("starting service...")
start_service()
......
......@@ -17,6 +17,10 @@ starting app via logcat works now
$ adb shell am start org.bd.p3service/org.kivy.android.PythonActivity
## start service via adb
$ adb shell am startservice org.bd.p3service/org.bd.p3service.ServiceTestp3serv
but still searching how to start it from an android app
resources in the net:
......
......@@ -36,7 +36,7 @@ version = 0.1
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3
requirements = python3, android
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
......@@ -214,7 +214,8 @@ p4a.source_dir = /home/phil/p4a
#p4a.hook =
# (str) Bootstrap to use for android builds
p4a.bootstrap = service_only
# p4a.bootstrap = service_only
p4a.bootstrap = sdl2
# (int) port number to specify an explicit --port= p4a argument (eg for bootstrap flask)
#p4a.port =
......
import socket
import json
import threading
import logging
logger=logging.getLogger("TestServ")
logger.setLevel(logging.INFO)
logger.info("hopp")
_STATUS_CODE_REQUEST = 0
_STATUS_CODE_GOOD_RESPONSE = 1
......@@ -283,6 +289,8 @@ class ProcBridgeServer:
server side of protocol
"""
num_connections = 10
def __init__(self, host, port, delegate):
"""
:param host:
......@@ -300,6 +308,7 @@ class ProcBridgeServer:
self.runlock = threading.Lock()
def start(self):
print("procbridge start")
self.lock.acquire()
try:
if self.started:
......@@ -307,8 +316,9 @@ class ProcBridgeServer:
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.socket.bind((self.host, self.port))
self.socket.listen(0)
# self.socket.bind((self.host, self.port))
self.socket.bind(('', self.port))
self.socket.listen(self.num_connections)
t = threading.Thread(target=_start_server_listener, args=(self,))
t.start()
self.started = True
......@@ -353,16 +363,20 @@ def _start_server_listener(server):
:param server: ProcBridgeServer instance
:return:
"""
print("_start_server_listener")
try:
print("start_server_listener:",server)
while True:
print("start_server_listener: before server.lock")
server.lock.acquire()
print("start_server_listener: after server.lock, server started?:", server.started)
if not server.started:
return
server.lock.release()
# assert started == true:
print("start_server_listener: before socket accept: server socket:", server.socket)
conn, _ = server.socket.accept()
print("start_server_listener: after socket accept:", conn)
t = threading.Thread(target=_start_connection, args=(server, conn,))
t.start()
# except ConnectionAbortedError:
......@@ -422,7 +436,9 @@ def _start_connection(server, s):
try:
print("_start_connection")
while server.started:
print("start_connectino: before read_request")
api, body = _read_request(s)
print("start_connectino: after read_request:", api, body)
print('api:', api, body)
if api == API_CLOSE:
print('closing')
......@@ -453,6 +469,7 @@ def _start_connection(server, s):
_write_bad_response(s, str(ex), resp_to=resp_to)
except Exception as e: #TODO: fix that seriously
print("start_connection:",str(e))
raise
finally:
s.close()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment