import socket
host='127.0.0.1'
port=8080
web=socket.socket()
web.bind((host,port))
web.listen(5)# 设置最多连接数
print('服务器等待客户端连接')
#开启死循环
while True:
coon,addr=web.accept()# 建立客户端连接
data=coon.recv(1024).decode()# 获取客户端请求数据
print(data)
coon.sendall(b'HTTP/1.1 200 ok\r\n\r\nhello world')
coon.close()

-------------------------------------------------------------------------------------------


import socket
s=socket.socket()
host='127.0.0.1'
port=8080
s.connect((host,port))
send_data=input('请输入要发送的数据:')
s.send(send_data.encode())
recvData=s.recv(1024).decode()
print('接收到的数据为:',recvData)
s.close()

创建TCP服务器和TCP客户端

创建TCP服务器和TCP客户端


 
                    
            
                

相关文章:

  • 2022-12-23
  • 2021-08-14
  • 2021-10-27
  • 2021-08-18
  • 2022-12-23
  • 2021-09-13
  • 2022-01-29
猜你喜欢
  • 2022-01-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-07
  • 2022-01-12
  • 2021-11-06
  • 2021-07-13
相关资源
相似解决方案