我正在为android创建一个小应用程序,它将向我的笔记本电脑发送文本数据。我用我的路由器创建了一个网络。在
客户端应用程序的代码是
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
import socket
Builder.load_string('''
<RootWidget>:
orientation: "vertical"
TextInput:
id: t1
size_hint_y: 75
Button:
text: "send data"
font_size: 75
size_hint_y: 25
on_press: root.send_data()
''')
class RootWidget(BoxLayout):
def __init__(self):
super(RootWidget, self).__init__()
host="10.0.0.5"
port=3000
self.s=socket.socket()
self.s.connect((host, port))
def send_data(self):
msg=str(self.ids.t1.text)
encoded_msg=bytes(msg, "utf-8")
self.s.send(encoded_msg)
class MyApp(App):
def build(self):
return RootWidget()
MyApp().run()
服务器在我的电脑终端上运行…它的代码是
^{pr2}$当我在笔记本电脑上运行服务器和客户端应用程序时,我得到了正确的结果
connection successful with ('10.0.0.5', 36719)
-> hello
^C
我用Buildozer制作了我的客户端应用程序的apk文件。当我试图从我的android手机上运行应用程序时,它会被连接起来,但当我在文本输入中输入文本并按下“发送数据”按钮时,应用程序终止,我在服务器终端上得到的输出是
connection successful with ('10.0.0.6', 35711)
connection with ('10.0.0.6', 35711) broken
^C
我无法解决在android上运行客户端应用程序的问题…需要帮助来解决这个问题吗
在您的文件中
buildozer.spec
更改现在用一个散列符号注释掉了, 为此:
^{pr2}$相关问题 更多 >
编程相关推荐