#server.py
import socket
from threading import Thread
def chat(conn):
    conn.send(b'hello')
    msg = conn.recv(1024).decode('utf-8')
    print(msg)
    conn.close()

sk = socket.socket()
sk.bind(('127.0.0.1',8080))
sk.listen()

while True:
    conn,addr = sk.accept()
    Thread(target=chat, args =(conn,)).start()
sk.close()


# client.py
import socket
sk = socket.socket()
sk.connect(('127.0.0.1',8080))
msg = sk.recv(1024)
print(msg)
inp = input('>>>').encode('utf-8')
sk.send(inp)
sk.close()

相关文章:

  • 2021-12-04
  • 2021-12-04
  • 2021-05-03
  • 2022-01-03
  • 2021-12-08
  • 2022-02-23
猜你喜欢
  • 2022-12-23
  • 2022-03-03
  • 2022-01-13
  • 2022-01-06
  • 2021-06-29
  • 2021-06-09
  • 2021-12-04
相关资源
相似解决方案