Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x I';我正在尝试使用Python 3.6制作聊天程序,但我想我可以';t保持连接_Python 3.x - Fatal编程技术网

Python 3.x I';我正在尝试使用Python 3.6制作聊天程序,但我想我可以';t保持连接

Python 3.x I';我正在尝试使用Python 3.6制作聊天程序,但我想我可以';t保持连接,python-3.x,Python 3.x,我想我可以连接服务器和客户端,然后我可以让服务器向客户端发送欢迎消息,客户端可以接收该消息 但在那个之后,我想我不能再保持服务器和客户端之间的连接了 我想让服务器和客户端在服务器向客户端发送欢迎消息,客户端向服务器发送消息,然后服务器再次向所有客户端发送消息后保持连接(是的,我正在尝试制作聊天程序。) 我正在使用Windows。我不确定我是否理解您的问题。我看到了你的代码,但我不明白它出了什么问题。为什么你认为你不能“保持联系”? import socket host = 'address'

我想我可以连接服务器和客户端,然后我可以让服务器向客户端发送欢迎消息,客户端可以接收该消息

但在那个之后,我想我不能再保持服务器和客户端之间的连接了

我想让服务器和客户端在服务器向客户端发送欢迎消息,客户端向服务器发送消息,然后服务器再次向所有客户端发送消息后保持连接(是的,我正在尝试制作聊天程序。)


我正在使用Windows。

我不确定我是否理解您的问题。我看到了你的代码,但我不明白它出了什么问题。为什么你认为你不能“保持联系”?
import socket

host = 'address' # as you know this isn't letters but I just write it as address for now.
port = 50000
bufsize = 1024

server = socket.socket()
server.bind((host, port))
server.listen(5) 

while 1:
 print("Waiting Connection")
 client, address = server.accept()
 print("Connected")
 welcomemsg = ("send messages")
 client.send(bytes(welcomemsg, "utf-8"))
 print("client info")
 print(address)
 msgfromclient = server.recv(bufsize).decode("utf8")
 client.send(bytes(msgfromclient, "utf-8"))
import socket

bufsize = 1024

client = socket.socket()

while 1:
 client.connect(('address', 50000))
 welcomemsg = client.recv(bufsize).decode("utf8")
 print(welcomemsg)
 msgtoserver = input()
 server.send(bytes(msgtoserver, "utf-8"))
 msgfromserver = client.recv(bufsize).decode("utf8")
 print(msgfromserver)