Python教程

近期Python

本文主要是介绍近期Python,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import socket
    

def main():
    client=socket.socket()
    client.connect(("127.0.0.1",8081))  
    while True:
        inputs=input(">>>").strip()
        client.send(len(inputs).to_bytes(1,byteorder="little",signed=False))
        client.send(inputs.encode())
        recvs=client.recv(1025)
        print(recvs.decode(encoding="utf-8"))    
if __name__=="__main__":
    main()

  

import socket
def process(conn,address):
    print("client connect :",conn,address)
    try:
        while True:
            data=conn.recv(1024)
            if len(data)==0:
                break
            else:
                print(data.decode())
                conn.send(data)
    except ConnectionResetError as e:
        print(e)    

def main():
    server=socket.socket()
    server.bind(("127.0.0.1",8081))
    server.listen(5)
    while True:
        conn,address=server.accept()
        process(conn,address)  
if __name__=="__main__":
    main()

  

这篇关于近期Python的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!