Python多线程聊天室报错
本帖最后由 编程追风梦 于 2023-7-7 16:37 编辑报错信息:
Traceback (most recent call last):
File "D:/卢天恩文件夹/31.高级编程工程/多线程图形化聊天软件/客户端/客户端.py", line 78, in <module>
s.connect(server)#建立连接
TimeoutError: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
客户端源代码
#客户端
import tkinter
from tkinter import font
import tkinter.messagebox
import socket
import threading
import time
string=''
def my_string(s_input):
string = s_input.get()
def Send(sock):
'''
发送数据的方法
参数:
sock:定义一个实例化socket对象
server:传递的服务器IP和端口
'''
if string!='':
message = name + ' : ' + string
data = message.encode('utf-8')
sock.send(data)
if string.lower() == 'EXIT'.lower():
exit()
def recv(sock):
sock.send(name.encode('utf-8'))
while True:
data = sock.recv(1024)
#加一个时间戳
time_tuple = time.localtime(time.time())
str = ("{}点{}分".format(time_tuple,time_tuple))
rrecv = tkinter.Label(t,text=data.decode('utf-8'),width=40,anchor='w',bg='pink')#接收的消息靠左边
rrecv.pack()
def left():
global string
string = rv1.get()
Send(s)
if string!='':
rleft = tkinter.Label(t,text=string,width=40,anchor='e')#发送的消息靠右边
rleft.pack()
rv1.set('')
def Creat():
global name
name = n.get()
#接收进程
tr = threading.Thread(target=recv, args=(s,), daemon=True)
# daemon=True 表示创建的子线程守护主线程,主线程退出子线程直接销毁
tr.start()
l.destroy()
e.destroy()
b.destroy()
t.title("聊天室")
t.geometry("500x600")
rL0 = tkinter.Label(t,text='%s的聊天室'%name,width=40)
rL0.pack()
rL1 = tkinter.Label(t,text='请输入消息:',width=20, height=1)
rL1.place(x=0,y=450)
rE1 = tkinter.Entry(t, textvariable = rv1)
rE1.place(x=200,y=450)
rB1 = tkinter.Button(t, text="发送",command=left)
rB1.place(x=380,y=450)
#发送进程
def JieShu():
tkinter.messagebox.showwarning(title='你确定退出吗?', message='刚才你点击了关闭按钮')
s.send("error1".encode('utf-8'))
exit(0)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server = ('10.100.207.40', 9999)
s.connect(server)#建立连接
t=tkinter.Tk()
t.title("多人聊天室")
t.geometry("300x200+500+200")
l = tkinter.Label(t,text='多人聊天室欢迎您,请输入你的名称',width=40, height=8)
l.pack()
n = tkinter.StringVar()
e = tkinter.Entry(t, width=15,textvariable = n)
e.pack()
rv1 = tkinter.StringVar()
name = n.get()
b = tkinter.Button(t, text="登录",width=40, height=10,command=Creat)
b.pack()
t.protocol("WM_DELETE_WINDOW", JieShu)
t.mainloop()
s.close()
不知道哪里出了问题
大佬们帮我看看
刚刚有人说是因为ip不对,要输入我自己的才行,我试了一下,还是不行,客户端的IP可能是随机的,所以我改成了我的上次访问IP
虽然没有显示报错,可以正常运行,但是发现过了一会会提示没有响应报错
于是我尝试改写admin服务端ip,结果直接报错
因为我ip是:119.111.249.139:43032
买随机的9999我改成了43032
还是显示报错,改回9999也一样报错
pip 该install的我也下载了,也有一些报错
(c) Microsoft Corporation。保留所有权利。
C:\Users\Administrator>pip install wxPython
Collecting wxPython
Downloading wxPython-4.2.1-cp312-cp312-win_amd64.whl (17.8 MB)
---------------------------------------- 17.8/17.8 MB 10.7 MB/s eta 0:00:00
Collecting pillow (from wxPython)
Downloading Pillow-10.0.0-cp312-cp312-win_amd64.whl (2.5 MB)
---------------------------------------- 2.5/2.5 MB 11.5 MB/s eta 0:00:00
Collecting six (from wxPython)
Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pillow, wxPython
Successfully installed pillow-10.0.0 six-1.16.0 wxPython-4.2.1
C:\Users\Administrator>pip install Tkinker
ERROR: Could not find a version that satisfies the requirement Tkinker (from versions: none)
ERROR: No matching distribution found for Tkinker
C:\Users\Administrator>pip install PyQt
ERROR: Could not find a version that satisfies the requirement PyQt (from versions: none)
ERROR: No matching distribution found for PyQt
C:\Users\Administrator>pip install PyGTK
Collecting PyGTK
Downloading pygtk-2.24.0.tar.bz2 (2.4 MB)
---------------------------------------- 2.4/2.4 MB 8.8 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... error
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─>
ERROR: Could not import dsextras module: Make sure you have installed pygobject.
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
C:\Users\Administrator>pip install Flexx
Collecting Flexx
Downloading flexx-0.8.4-py2.py3-none-any.whl (351 kB)
---------------------------------------- 351.6/351.6 kB 5.4 MB/s eta 0:00:00
Collecting tornado (from Flexx)
Downloading tornado-6.3.2-cp38-abi3-win_amd64.whl (428 kB)
---------------------------------------- 428.4/428.4 kB 8.9 MB/s eta 0:00:00
Collecting pscript>=0.7.7 (from Flexx)
Downloading pscript-0.7.7-py3-none-any.whl (126 kB)
---------------------------------------- 126.7/126.7 kB 7.3 MB/s eta 0:00:00
Collecting webruntime>=0.5.6 (from Flexx)
Downloading webruntime-0.5.8-py3-none-any.whl (53 kB)
---------------------------------------- 53.7/53.7 kB 2.9 MB/s eta 0:00:00
Collecting dialite>=0.5.2 (from Flexx)
Downloading dialite-0.5.3-py3-none-any.whl (8.8 kB)
Installing collected packages: pscript, dialite, webruntime, tornado, Flexx
Successfully installed Flexx-0.8.4 dialite-0.5.3 pscript-0.7.7 tornado-6.3.2 webruntime-0.5.8
C:\Users\Administrator>pip install Kivy
Collecting Kivy
Downloading Kivy-2.2.1.tar.gz (24.0 MB)
---------------------------------------- 24.0/24.0 MB 4.7 MB/s eta 0:00:00
Installing build dependencies ... error
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─>
Collecting setuptools
Using cached setuptools-68.0.0-py3-none-any.whl (804 kB)
Collecting wheel
Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
Collecting packaging
Downloading packaging-23.1-py3-none-any.whl (48 kB)
---------------------------------------- 48.9/48.9 kB ? eta 0:00:00
Collecting cython!=0.27,!=0.27.2,<=0.29.33,>=0.24
Downloading Cython-0.29.33-py2.py3-none-any.whl (987 kB)
-------------------------------------- 987.3/987.3 kB 7.8 MB/s eta 0:00:00
ERROR: Could not find a version that satisfies the requirement kivy_deps.gstreamer_dev~=0.3.3 (from versions: none)
ERROR: No matching distribution found for kivy_deps.gstreamer_dev~=0.3.3
note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error
× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.
note: This error originates from a subprocess, and is likely not a problem with pip.
C:\Users\Administrator>pip install GUI
ERROR: Could not find a version that satisfies the requirement GUI (from versions: none)
ERROR: No matching distribution found for GUI
C:\Users\Administrator>pip install PyGame
Requirement already satisfied: PyGame in c:\users\administrator\appdata\local\programs\python\python312\lib\site-packages (2.5.0) 陶远航 发表于 2023-7-7 16:23
您好!根据您提供的错误信息,问题出在连接服务器的部分。这是错误信息:
主要是我这个admin都是可以正常运行的 编程追风梦 发表于 2023-7-7 16:24
主要是我这个admin都是可以正常运行的
对不起,我这个用的是gpt4接口,有点慢 陶远航 发表于 2023-7-7 16:28
对不起,我这个用的是gpt4接口,有点慢
哦没事,我应该怎么改?是ip的问题?改成我自己的ip了也没用,还是显示报错 编程追风梦 发表于 2023-7-7 16:31
哦没事,我应该怎么改?是ip的问题?改成我自己的ip了也没用,还是显示报错
这个我也不会 陶远航 发表于 2023-7-7 16:28
对不起,我这个用的是gpt4接口,有点慢
兄弟有钱啊{:10_275:} 陶远航 发表于 2023-7-7 16:40
这个我也不会
哦好吧 你有新电话了吗?今天我大概十点到成都 你这个是服务器还是啥
我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0 Mike_python小 发表于 2023-7-7 20:36
你这个是服务器还是啥
我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0
你的服务器可否开下{:10_254:}
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器 歌者文明清理员 发表于 2023-7-7 22:19
你的服务器可否开下
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器
hmm,哪里购买?有镜像的吗? 学习编程中的Ben 发表于 2023-7-7 20:21
你有新电话了吗?今天我大概十点到成都
我们提前去提前回来了 Mike_python小 发表于 2023-7-7 20:36
你这个是服务器还是啥
我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0
我试过了,好像有用诶!最佳答案给你啦 歌者文明清理员 发表于 2023-7-7 22:19
你的服务器可否开下
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器
我这服务器也到期了啊,最近都没咋搞{:10_266:}
页:
[1]