[英]Errno111 Connection Refused Kivy Socket Error
I am a new beginner in kivy I am developing a app that connect to my windows pc using python sockets我是 kivy 的新初学者 我正在开发一个应用程序,该应用程序使用 python ZFFE33A13F6E35006DABAB7D7F6E35004windows 电脑连接到我的电脑
This is my Kivy App code:这是我的 Kivy 应用程序代码:
import kivy
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
import socket
class FloatLay(FloatLayout):
def Connect(self):
try:
s = socket.socket()
hostname = '127.0.0.1'
port = 8080
s.connect((hostname, port))
except Exception as e:
self.ids.text.text = str(e)
class MyApp(App):
def build(self):
return FloatLay()
if __name__ == "__main__":
MyApp().run()
This is my.kv kivy file这是 my.kv kivy 文件
<FloatLay>:
Button:
text:"Connect"
pos_hint:{"x":0.6,"top":0.5}
size_hint:0.1,0.05
on_press: root.Connect()
Label:
id:text
text:"Connect Status"
pos_hint:{"x":0.2,"top":0.5}
size_hint:0.4,0.05
This is my Socket_Server这是我的 Socket_Server
import socket
def main():
while True:
running=False
listensocket = socket.socket()
Port = 8080
maxConnections = 999
IP = '127.0.0.1' #IP address of local machine
listensocket.bind((IP,Port))
listensocket.listen(maxConnections)
print("Server started at " + IP + " on port " + str(Port))
(clientsocket, address) = listensocket.accept()
print("New connection made!")
running = True
try:
while running:
message = clientsocket.recv(1024).decode()
print(message)
except:
print('')
main()
Whenever I run the code their is a error named Connection Refused每当我运行代码时,它们都会出现一个名为 Connection Refused 的错误
I dont think their is a mistake in my code as when i run the Client code and the Server on my windows pc at the same time they both are connected.我不认为它们是我的代码中的错误,因为当我在我的 windows pc 上同时运行客户端代码和服务器时,它们都已连接。
Note:I am running the App on a android device and the code on a windows pc
注意:我在 android 设备上运行应用程序,在 windows 电脑上运行代码
I have got the solution for this if you are using windows then follow these steps:如果您使用的是 windows,我已经找到了解决方案,然后按照以下步骤操作:
ipconfig
ipconfig
Wireless LAN adapter Wi-Fi
sectionWireless LAN adapter Wi-Fi
部分中找到 IPv4Note: Dont add any spaces while typing the IP
注意:输入 IP 时不要添加任何空格
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.