Я сделал приложение с Python и Kivy.Он отлично работает на моем компьютере, но когда я собрал приложение с помощью buildozer и открыл его на своем телефоне Android, он не отправлял никаких данных.он сказал, что подключен и показывает правильный IP.Я установил для разрешения INTERNET значение true в спецификации buildozer.это мой код PS.извините за мой плохой английский
-> это основной код приложения
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.textinput import TextInput
from kivy.uix.scatter import Scatter
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.uix.label import Label
from kivy.config import Config
from kivy.app import App
import threading
import socket
import time
import os
# set screen height and with
Config.set('graphics', 'height', '600')
Config.set('graphics', 'width', '350')
mousePos = ""
class MainApp(FloatLayout):
# mousePos movement
def on_touch_move(self, touch):
global mousePos #
x = str(touch) # i really don't know how
list = x.split (' ') # butt it works
mousePos = list[3:] #
# sent mousePos to screen
self.ids.Texthi.text = str(mousePos)
def connected(self):
def tryToConnect():
print("tryToConnect")
getCustomIP = self.ids.getCustomIP.text
getCustomPORT = self.ids.getCustomPORT.text
self.ids.connectToServer.text = "connecting to \"" + getCustomIP + "\" on port " + getCustomPORT
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
s.connect((getCustomIP, int(getCustomPORT)))
self.ids.connectToServer.text = "connected to \"" + getCustomIP + "\" on port " + getCustomPORT
print("connected")
except Exception as e:
print(e)
self.ids.connectToServer.text = "connection faild pls try again!"
return
print("start sending data in Lööps")
x = 1
while x == 1:
time.sleep(0.5) # so i don't destroy the network
try:
mousePosStrByte = bytes(str(mousePos), 'utf-8') #something to string to bytes
s.send(mousePosStrByte) # send to client
except Exception as e:
#self.ids.connectToServer.text = e
print(e)
self.ids.connectToServer.text = "your victim has disconnected"
x = 0
print("2" , x)
s.close()
print("start thread 1 tryToConnect")
our_thread = threading.Thread( target=tryToConnect, name="thread 1")
our_thread.start()
class TestApp(App):
def build(self):
return MainApp()
if __name__ == '__main__':
TestApp().run()
-> это файл kv
<FloatLayout>
Label:
id: connectToServer
text: "connect to a server"
pos_hint: {"left":0, "top":.93}
size_hint: 3,.064
halign: 'left'
text_size: self.size
Label:
id: Texthi
pos_hint: {"left":0, "top":.80}
size_hint: 3,.064
halign: 'left'
text_size: self.size
Button:
text: "Connect the server"
pos_hint: {"right":1, "top":0.949}
on_release: root.connected()
size_hint: 1,0.05
TextInput:
id: getCustomIP
multiline: False
text: "192.168.2.XX"
pos_hint: {"left":0, "top":1}
size_hint: 0.5,0.05
TextInput:
id: getCustomPORT
multiline: False
text: "1235"
pos_hint: {"right":1, "top":1}
size_hint: 0.5,0.05
-> иэто клиентский код
import socket
import subprocess
import time
b = '[pos=(\')>,]'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("0.0.0.0",1235))
s.listen(1)
conn, addr = s.accept()
print("connected to " , addr)
bbbb = ""
while 1:
clientdata = conn.recv(1024)
mousePosStr = clientdata.decode("utf-8")
if (mousePosStr != bbbb):
bbbb = mousePosStr
for char in b:
mousePosStr = mousePosStr.replace(char,"")
list = mousePosStr.split (' ')
yAxis = list[0]
xAxis = list[1]
print (yAxis,xAxis)