5.17练习python

1
import socket
host = socket.gethostname()
port=8081
serversock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
serversock.bind((host,port))
serversock.listen(5)
print('等待客户端连接')
while True:
    clientsocket,addr=serversock.accept()
    data = clientsocket.recv(1024)
    print(data)
    msg='hello'
    clientsocket.sendall(msg.encode('utf-8'))
    clientsocket.close()


2
import socket
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
host = socket.gethostname()
port=8081
sock.connect((host,port))
senddata=input("请输入:")
sock.send(senddata.encode())
recedata=sock.recv(1024)
print(recedata.decode("utf-8"))
sock.close()
温馨提示:本文最后更新于2024-05-17 15:10:25,某些文章具有时效性,若有错误或已失效,请在下方留言或联系站长
© 版权声明
THE END
喜欢就支持一下吧
点赞1 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情

    暂无评论内容