server-----------------
#!/usr/bin/env python
# encoding: utf-8  
# Date: 2018/6/5


import socket

phone = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
phone.bind(('127.0.0.1', 8081))
phone.listen(5)

print('starting.......')
conn, client_addr = phone.accept()
print(client_addr)

while True:
    data = conn.recv(1024)
    print('客户端的数据', data)

    conn.send(data.upper())

conn.close()
phone.close()

client--------------------
#!/usr/bin/env python
# encoding: utf-8  
# Date: 2018/6/5


import socket

phone = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
phone.connect(('127.0.0.1', 8081))

while True:
    msg = input('>>>').strip()
    phone.send(msg.encode('utf-8'))
    data = phone.recv(1024)
    print(data.decode('utf-8'))

phone.close()



相关文章:

  • 2021-10-18
猜你喜欢
  • 2021-11-27
  • 2021-07-31
  • 2022-12-23
  • 2021-09-19
  • 2021-08-20
  • 2021-10-21
  • 2021-09-13
相关资源
相似解决方案