[mess] [python] Naive Echo Server

2021-07-16 10:06

阅读:821

标签:soc   nec   input   print   imp   str   bre   line   ESS   

# server.py
from socket import *

HOST = ‘‘
PORT = 50007

s = socket(AF_INET, SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
(conn, addr) = s.accept()

while True:
  data = conn.recv(1024)
  if not data:
    break
  conn.send(data)

conn.close()
# client.py
from socket import *

HOST = ‘‘
PORT = 50007

s = socket(AF_INET, SOCK_STREAM)
s.connect((HOST, PORT))

while True:
  line = input()
  if not line:
    break
  s.send(str.encode(line))
  data = s.recv(1024)
  print(data)

s.close()

[mess] [python] Naive Echo Server

标签:soc   nec   input   print   imp   str   bre   line   ESS   

原文地址:https://www.cnblogs.com/wander4096/p/9534745.html


评论


亲,登录后才可以留言!