鱼C论坛

 找回密码
 立即注册
查看: 1604|回复: 14

[已解决]Python多线程聊天室报错

[复制链接]
发表于 2023-7-7 16:22:26 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 编程追风梦 于 2023-7-7 16:37 编辑

报错信息:

  1. Traceback (most recent call last):
  2.   File "D:/卢天恩文件夹/31.高级编程工程/多线程图形化聊天软件/客户端/客户端.py", line 78, in <module>
  3.     s.connect(server)#建立连接
  4. TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
复制代码



客户端源代码
  1. #客户端
  2. import tkinter
  3. from tkinter import font
  4. import tkinter.messagebox
  5. import socket
  6. import threading
  7. import time

  8. string=''
  9. def my_string(s_input):
  10.     string = s_input.get()

  11. def Send(sock):
  12.     '''
  13.         发送数据的方法
  14.         参数:
  15.             sock:定义一个实例化socket对象
  16.             server:传递的服务器IP和端口
  17.     '''
  18.     if string!='':
  19.         message = name + ' : ' + string
  20.         data = message.encode('utf-8')
  21.         sock.send(data)
  22.         if string.lower() == 'EXIT'.lower():
  23.             exit()


  24. def recv(sock):
  25.     sock.send(name.encode('utf-8'))
  26.     while True:
  27.         data = sock.recv(1024)
  28.         #加一个时间戳
  29.         time_tuple = time.localtime(time.time())
  30.         str = ("{}点{}分".format(time_tuple[3],time_tuple[4]))
  31.         rrecv = tkinter.Label(t,text=data.decode('utf-8'),width=40,anchor='w',bg='pink')#接收的消息靠左边
  32.         rrecv.pack()

  33. def left():
  34.     global string
  35.     string = rv1.get()
  36.     Send(s)
  37.     if string!='':
  38.         rleft = tkinter.Label(t,text=string,width=40,anchor='e')#发送的消息靠右边
  39.         rleft.pack()
  40.         rv1.set('')

  41. def Creat():
  42.     global name
  43.     name = n.get()
  44.    
  45.     #接收进程
  46.     tr = threading.Thread(target=recv, args=(s,), daemon=True)
  47.     # daemon=True 表示创建的子线程守护主线程,主线程退出子线程直接销毁
  48.     tr.start()
  49.      
  50.     l.destroy()
  51.     e.destroy()
  52.     b.destroy()
  53.     t.title("聊天室")
  54.     t.geometry("500x600")
  55.     rL0 = tkinter.Label(t,text='%s的聊天室'%name,width=40)
  56.     rL0.pack()
  57.     rL1 = tkinter.Label(t,text='请输入消息:',width=20, height=1)
  58.     rL1.place(x=0,y=450)
  59.     rE1 = tkinter.Entry(t, textvariable = rv1)
  60.     rE1.place(x=200,y=450)
  61.     rB1 = tkinter.Button(t, text="发送",command=left)  
  62.     rB1.place(x=380,y=450)
  63.     #发送进程

  64. def JieShu():
  65.     tkinter.messagebox.showwarning(title='你确定退出吗?', message='刚才你点击了关闭按钮')
  66.     s.send("error1".encode('utf-8'))
  67.     exit(0)   
  68.    
  69. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)   
  70. server = ('10.100.207.40', 9999)
  71. s.connect(server)#建立连接
  72. t=tkinter.Tk()
  73. t.title("多人聊天室")
  74. t.geometry("300x200+500+200")
  75. l = tkinter.Label(t,text='多人聊天室欢迎您,请输入你的名称',width=40, height=8)
  76. l.pack()
  77. n = tkinter.StringVar()
  78. e = tkinter.Entry(t, width=15,textvariable = n)
  79. e.pack()
  80. rv1 = tkinter.StringVar()
  81. name = n.get()

  82. b = tkinter.Button(t, text="登录",width=40, height=10,command=Creat)

  83. b.pack()
  84. t.protocol("WM_DELETE_WINDOW", JieShu)
  85. t.mainloop()

  86. s.close()
复制代码
不知道哪里出了问题
大佬们帮我看看



刚刚有人说是因为ip不对,要输入我自己的才行,我试了一下,还是不行,客户端的IP可能是随机的,所以我改成了我的上次访问IP

客户端报错

客户端报错

虽然没有显示报错,可以正常运行,但是发现过了一会会提示没有响应报错

于是我尝试改写admin服务端ip,结果直接报错

admin报错

admin报错

因为我ip是:119.111.249.139:43032
买随机的9999我改成了43032

个人主页

个人主页

还是显示报错,改回9999也一样报错
最佳答案
2023-7-7 20:36:22
你这个是服务器还是啥

我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2023-7-7 16:23:13 | 显示全部楼层
pip 该install的我也下载了,也有一些报错
  1. (c) Microsoft Corporation。保留所有权利。

  2. C:\Users\Administrator>pip install wxPython
  3. Collecting wxPython
  4.   Downloading wxPython-4.2.1-cp312-cp312-win_amd64.whl (17.8 MB)
  5.      ---------------------------------------- 17.8/17.8 MB 10.7 MB/s eta 0:00:00
  6. Collecting pillow (from wxPython)
  7.   Downloading Pillow-10.0.0-cp312-cp312-win_amd64.whl (2.5 MB)
  8.      ---------------------------------------- 2.5/2.5 MB 11.5 MB/s eta 0:00:00
  9. Collecting six (from wxPython)
  10.   Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
  11. Installing collected packages: six, pillow, wxPython
  12. Successfully installed pillow-10.0.0 six-1.16.0 wxPython-4.2.1

  13. C:\Users\Administrator>pip install Tkinker
  14. ERROR: Could not find a version that satisfies the requirement Tkinker (from versions: none)
  15. ERROR: No matching distribution found for Tkinker

  16. C:\Users\Administrator>pip install PyQt
  17. ERROR: Could not find a version that satisfies the requirement PyQt (from versions: none)
  18. ERROR: No matching distribution found for PyQt

  19. C:\Users\Administrator>pip install PyGTK
  20. Collecting PyGTK
  21.   Downloading pygtk-2.24.0.tar.bz2 (2.4 MB)
  22.      ---------------------------------------- 2.4/2.4 MB 8.8 MB/s eta 0:00:00
  23.   Installing build dependencies ... done
  24.   Getting requirements to build wheel ... error
  25.   error: subprocess-exited-with-error

  26.   × Getting requirements to build wheel did not run successfully.
  27.   │ exit code: 1
  28.   ╰─> [1 lines of output]
  29.       ERROR: Could not import dsextras module: Make sure you have installed pygobject.
  30.       [end of output]

  31.   note: This error originates from a subprocess, and is likely not a problem with pip.
  32. error: subprocess-exited-with-error

  33. × Getting requirements to build wheel did not run successfully.
  34. │ exit code: 1
  35. ╰─> See above for output.

  36. note: This error originates from a subprocess, and is likely not a problem with pip.

  37. C:\Users\Administrator>pip install Flexx
  38. Collecting Flexx
  39.   Downloading flexx-0.8.4-py2.py3-none-any.whl (351 kB)
  40.      ---------------------------------------- 351.6/351.6 kB 5.4 MB/s eta 0:00:00
  41. Collecting tornado (from Flexx)
  42.   Downloading tornado-6.3.2-cp38-abi3-win_amd64.whl (428 kB)
  43.      ---------------------------------------- 428.4/428.4 kB 8.9 MB/s eta 0:00:00
  44. Collecting pscript>=0.7.7 (from Flexx)
  45.   Downloading pscript-0.7.7-py3-none-any.whl (126 kB)
  46.      ---------------------------------------- 126.7/126.7 kB 7.3 MB/s eta 0:00:00
  47. Collecting webruntime>=0.5.6 (from Flexx)
  48.   Downloading webruntime-0.5.8-py3-none-any.whl (53 kB)
  49.      ---------------------------------------- 53.7/53.7 kB 2.9 MB/s eta 0:00:00
  50. Collecting dialite>=0.5.2 (from Flexx)
  51.   Downloading dialite-0.5.3-py3-none-any.whl (8.8 kB)
  52. Installing collected packages: pscript, dialite, webruntime, tornado, Flexx
  53. Successfully installed Flexx-0.8.4 dialite-0.5.3 pscript-0.7.7 tornado-6.3.2 webruntime-0.5.8

  54. C:\Users\Administrator>pip install Kivy
  55. Collecting Kivy
  56.   Downloading Kivy-2.2.1.tar.gz (24.0 MB)
  57.      ---------------------------------------- 24.0/24.0 MB 4.7 MB/s eta 0:00:00
  58.   Installing build dependencies ... error
  59.   error: subprocess-exited-with-error

  60.   × pip subprocess to install build dependencies did not run successfully.
  61.   │ exit code: 1
  62.   ╰─> [12 lines of output]
  63.       Collecting setuptools
  64.         Using cached setuptools-68.0.0-py3-none-any.whl (804 kB)
  65.       Collecting wheel
  66.         Using cached wheel-0.40.0-py3-none-any.whl (64 kB)
  67.       Collecting packaging
  68.         Downloading packaging-23.1-py3-none-any.whl (48 kB)
  69.            ---------------------------------------- 48.9/48.9 kB ? eta 0:00:00
  70.       Collecting cython!=0.27,!=0.27.2,<=0.29.33,>=0.24
  71.         Downloading Cython-0.29.33-py2.py3-none-any.whl (987 kB)
  72.            -------------------------------------- 987.3/987.3 kB 7.8 MB/s eta 0:00:00
  73.       ERROR: Could not find a version that satisfies the requirement kivy_deps.gstreamer_dev~=0.3.3 (from versions: none)
  74.       ERROR: No matching distribution found for kivy_deps.gstreamer_dev~=0.3.3
  75.       [end of output]

  76.   note: This error originates from a subprocess, and is likely not a problem with pip.
  77. error: subprocess-exited-with-error

  78. × pip subprocess to install build dependencies did not run successfully.
  79. │ exit code: 1
  80. ╰─> See above for output.

  81. note: This error originates from a subprocess, and is likely not a problem with pip.

  82. C:\Users\Administrator>pip install GUI
  83. ERROR: Could not find a version that satisfies the requirement GUI (from versions: none)
  84. ERROR: No matching distribution found for GUI

  85. C:\Users\Administrator>pip install PyGame
  86. Requirement already satisfied: PyGame in c:\users\administrator\appdata\local\programs\python\python312\lib\site-packages (2.5.0)
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-7 16:24:38 | 显示全部楼层
陶远航 发表于 2023-7-7 16:23
您好!根据您提供的错误信息,问题出在连接服务器的部分。这是错误信息:

主要是我这个admin都是可以正常运行的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 16:28:09 | 显示全部楼层
编程追风梦 发表于 2023-7-7 16:24
主要是我这个admin都是可以正常运行的

对不起,我这个用的是gpt4接口,有点慢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-7 16:31:37 | 显示全部楼层
陶远航 发表于 2023-7-7 16:28
对不起,我这个用的是gpt4接口,有点慢

哦没事,我应该怎么改?是ip的问题?改成我自己的ip了也没用,还是显示报错
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 16:40:26 | 显示全部楼层
编程追风梦 发表于 2023-7-7 16:31
哦没事,我应该怎么改?是ip的问题?改成我自己的ip了也没用,还是显示报错

这个我也不会
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 18:47:00 | 显示全部楼层
陶远航 发表于 2023-7-7 16:28
对不起,我这个用的是gpt4接口,有点慢

兄弟有钱啊
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-7 18:49:16 | 显示全部楼层

哦好吧
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 20:21:33 From FishC Mobile | 显示全部楼层
你有新电话了吗?今天我大概十点到成都
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 20:36:22 | 显示全部楼层    本楼为最佳答案   
你这个是服务器还是啥

我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-7 22:19:52 | 显示全部楼层
Mike_python小 发表于 2023-7-7 20:36
你这个是服务器还是啥

我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0

你的服务器可否开下
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-8 08:29:16 | 显示全部楼层
歌者文明清理员 发表于 2023-7-7 22:19
你的服务器可否开下
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器

hmm,哪里购买?有镜像的吗?
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-8 08:30:33 | 显示全部楼层
学习编程中的Ben 发表于 2023-7-7 20:21
你有新电话了吗?今天我大概十点到成都

我们提前去提前回来了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2023-7-8 08:31:04 | 显示全部楼层
Mike_python小 发表于 2023-7-7 20:36
你这个是服务器还是啥

我不知道你原来咋写的,反正ip那一栏服务端要写成0.0.0.0

我试过了,好像有用诶!最佳答案给你啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2023-7-8 08:42:45 | 显示全部楼层
歌者文明清理员 发表于 2023-7-7 22:19
你的服务器可否开下
另外他这个是直接把自己的ip用来当服务器ip了,他应该没有购买服务器

我这服务器也到期了啊,最近都没咋搞
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-23 18:30

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表