Python搭建会话服务器

原创
2017/05/04 22:05
阅读数 165
import socket

host = "localhost"
port = 50001

comms_socket = socket.socket()
comms_socket.bind((host, port))

comms_socket.listen(10)
connection, address = comms_socket.accept()

while True:
  print(connection.recv(4609).decode("UTF-8"))
  result_data = input("Reply:")
  connection.send(bytes(result_data, "UTF-8"))

以上为server端的代码

客户端的代码

import socket

host = "localhost"
port = 50001

comms_socket = socket.socket()
comms_socket.connect((host, port))

while True:
  send_data = input("request_data:")
  comms_socket.send(bytes(send_data, "UTF-8"))
  print(comms_socket.recv(4609).decode("UTF-8"))

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部