Commit 887cb37a authored by Philipp Auersperg's avatar Philipp Auersperg

connection to android works

parent 608f38a5
......@@ -56,7 +56,7 @@ orientation = portrait
# (list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
services = Serv:serv.py
services = TestServ:serv.py
#
# OSX Specific
#
......
......@@ -26,7 +26,7 @@ class MainWindow(BoxLayout):
print 'starting service...'
if platform == 'android':
from jnius import autoclass
service = autoclass('org.bd.servicetest.ServiceServ')
service = autoclass('org.bd.servicetest.ServiceTestserv')
mActivity = autoclass('org.kivy.android.PythonActivity').mActivity
argument = ''
res=service.start(mActivity, argument)
......
......@@ -2,16 +2,16 @@
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"@file:DependsOnMaven(\"co.gongzh.procbridge:procbridge:2.0.0-gson\")"
"@file:DependsOnMaven(\"co.gongzh.procbridge:procbridge:2.1.0-gradle\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -33,55 +33,23 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"java.lang.RuntimeException: Socket can not be connected.\n",
"\tat co.gongzh.procbridge.ProcBridge.<init>(ProcBridge.java:54)\n",
"Caused by: java.net.ConnectException: Verbindungsaufbau abgelehnt\n",
"\tat java.net.PlainSocketImpl.socketConnect(Native Method)\n",
"\tat java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)\n",
"\tat java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)\n",
"\tat java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)\n",
"\tat java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)\n",
"\tat java.net.Socket.connect(Socket.java:589)\n",
"\tat co.gongzh.procbridge.ProcBridge.<init>(ProcBridge.java:46)\n",
"\tat Line_9.<init>(Unknown Source)\n",
"\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n",
"\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\n",
"\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n",
"\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\n",
"\tat org.jetbrains.kotlin.cli.common.repl.GenericReplEvaluator.eval(GenericReplEvaluator.kt:95)\n",
"\tat org.jetbrains.kotlin.cli.common.repl.GenericReplCompilingEvaluator.eval(GenericReplCompilingEvaluator.kt:74)\n",
"\tat org.jetbrains.kotlin.cli.common.repl.GenericReplCompilingEvaluator.compileAndEval(GenericReplCompilingEvaluator.kt:49)\n",
"\tat uy.kohesive.keplin.kotlin.script.SimplifiedRepl.compileAndEval(SimplifiedRepl.kt:113)\n",
"\tat uy.kohesive.keplin.kotlin.script.SimplifiedRepl.compileAndEval$default(SimplifiedRepl.kt:112)\n",
"\tat org.jetbrains.kotlin.jupyter.ReplForJupyter.eval(repl.kt:41)\n",
"\tat org.jetbrains.kotlin.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt:61)\n",
"\tat org.jetbrains.kotlin.jupyter.ProtocolKt$shellMessagesHandler$res$1.invoke(protocol.kt)\n",
"\tat org.jetbrains.kotlin.jupyter.ProtocolKt.evalWithIO(protocol.kt:165)\n",
"\tat org.jetbrains.kotlin.jupyter.ProtocolKt.shellMessagesHandler(protocol.kt:60)\n",
"\tat org.jetbrains.kotlin.jupyter.IkotlinKt.kernelServer(ikotlin.kt:83)\n",
"\tat org.jetbrains.kotlin.jupyter.IkotlinKt.main(ikotlin.kt:41)"
]
}
],
"outputs": [],
"source": [
"val host = \"127.0.0.1\"\n",
"val port = 8877\n",
"// val host = \"127.0.0.1\"\n",
"val host = \"192.168.1.19\"\n",
"\n",
"val port = 8077\n",
"val timeout = 10000 // 10 seconds\n",
"\n",
"class Handler: MessageHandler {\n",
" override fun onMessage(message: JsonObject) {\n",
" val x=1/0\n",
" TODO(\"not implemented\") //To change body of created functions use File | Settings | File Templates.\n",
"// val x=1/0\n",
"// TODO(\"not implemented\") //To change body of created functions use File | Settings | File Templates.\n",
" }\n",
" override fun onError(e: ProcBridgeException?) {\n",
" TODO(\"not implemented\") //To change body of created functions use File | Settings | File Templates.\n",
"// TODO(\"not implemented\") //To change body of created functions use File | Settings | File Templates.\n",
" }\n",
"}\n",
"\n",
......@@ -92,38 +60,110 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"sending text:{}\n",
"wrote data:[B@3b47adeb\n",
"sending text:{elements: [1, 2, 3, 4, 5]}\n",
"wrote data:[B@68ebc1ed\n"
]
}
],
"outputs": [],
"source": [
"\n",
"// val resp = \n",
"pb.sendMessage(\"echo\", \"{}\")\n",
"val res1=pb.sendMessage(\"echo\", \"{echo:schas}\")\n",
"// println(resp) // prints \"{}\"\n",
"\n",
"// val resp1 = \n",
"pb.sendMessage(\"add\", \"{elements: [1, 2, 3, 4, 5]}\")\n",
"val res2=pb.sendMessage(\"add\", \"{elements: [1, 2, 3, 4, 5]}\")\n",
"// println(resp1) // prints \"{result: 15}\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"java.util.concurrent.CompletableFuture@74ba0d7[Not completed]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res1"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\"result\":15}"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res2.get()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{\"result\":\"Hello:schas\"}"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"res1.get()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"pb"
"val res3=pb.sendMessage(\"geterror\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"wazzup\n",
"java.util.concurrent.ExecutionException: co.gongzh.procbridge.ProcBridgeException: shit happened\n"
]
}
],
"source": [
"try{\n",
" res3.get()\n",
"} catch (e: Exception ){\n",
" println(\"wazzup\")\n",
" println(e)\n",
"}"
]
},
{
......
print "------------------------------------------serv"
import time
import procbridge
print 'procbridge imported'
......@@ -8,14 +9,27 @@ delegate = procbridge.Delegate()
@delegate.api
def echo(self, echo, **kw):
print "echo:", echo
time.sleep(3)
return "Hello:" + echo
@delegate.api
def shutdown(self, **kw):
self.server.stop()
@delegate.api
def add(self, elements, conn, **kw):
# return {'result': sum(x for x in elements)} #long version
for i in elements:
self.server.write_back(conn, {'element':i})
return sum(elements)
@delegate.api
def geterror(self, **kw):
raise Exception("shit happened")
def runit():
host = '127.0.0.1'
host = '0.0.0.0'
port = 8077
# start socket server
......
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