zoukankan      html  css  js  c++  java
  • 创建TCP服务器和TCP客户端

    import socket
    host='127.0.0.1'
    port=8080
    web=socket.socket()
    web.bind((host,port))
    web.listen(5)# 设置最多连接数
    print('服务器等待客户端连接')
    #开启死循环
    while True:
    coon,addr=web.accept()# 建立客户端连接
    data=coon.recv(1024).decode()# 获取客户端请求数据
    print(data)
    coon.sendall(b'HTTP/1.1 200 ok hello world')
    coon.close()

    -------------------------------------------------------------------------------------------


    import socket
    s=socket.socket()
    host='127.0.0.1'
    port=8080
    s.connect((host,port))
    send_data=input('请输入要发送的数据:')
    s.send(send_data.encode())
    recvData=s.recv(1024).decode()
    print('接收到的数据为:',recvData)
    s.close()

    
    
  • 相关阅读:
    Redis 补充
    python 魔法方法补充(__setattr__,__getattr__,__getattribute__)
    Mongodb 补充
    Mysql补充
    HTML
    优秀工具
    优秀文章收藏
    MySQL
    爬虫
    Python
  • 原文地址:https://www.cnblogs.com/startl/p/12061446.html
Copyright © 2011-2022 走看看