zoukankan      html  css  js  c++  java
  • day_5.28 py网络编程

    端口

    socket简介:

    socket为一个类   s接收的是返回的对象引用

    2018-5-28 15:52:47
    开始进行网络编程
    udp 套接字
    encode() 编码 decode() 解码
    '''
    from socket import *
    
    #创建一个udp套接字
    udpSocket = socket(AF_INET,SOCK_DGRAM)
    # 使用udp发送的数据,在每一次的都需要写上接收方的ip和port
    udpSocket.sendto(b"haha",("192.168.19.15",8080)) #传入参数内容,("IP",端口号)
    # 绑定端口,如果不绑定,则系统分配 (接收方需要绑定数据,发送方不需要绑定)
    udpSocket.bind("",7788)
    #等待接受对方发送的数据
    recvDate = udpSocket.recvfrom(1021) #1024表示本次接收的最大字节数
    #接收数据为元组:  (数据,ip)
    content,destInfo = recvDate
    print("content is %s"%content.decode("utf-8"))
    # 显式接收的数据
    print(recvDate)
    #创建一个tcp套接字
    # tcpSocket = socket.socket(AF_INET,SOCK_STREAM)
    
    #udp套接字发送数据优化 解决第14行在数据前加b的问题(python3会出现)
    udpSocket = socket(AF_INET,SOCK_DGRAM)
    destIP = input("请输入目的ip:")
    destPort = int(input("请输入目的port:"))
    sendData = input("请输入要发送的数据:")
    udpSocket.sendto(sendData.encode("utf-8"),(destInfo,destPort))
    

      

    2018-5-28 15:52:47
    开始进行网络编程
    udp 套接字
    encode() 编码 decode() 解码
    '''
    from socket import *

    #创建一个udp套接字
    udpSocket = socket(AF_INET,SOCK_DGRAM)
    # 使用udp发送的数据,在每一次的都需要写上接收方的ip和port
    udpSocket.sendto(b"haha",("192.168.19.15",8080)) #传入参数内容,("IP",端口号)
    # 绑定端口,如果不绑定,则系统分配 (接收方需要绑定数据,发送方不需要绑定)
    udpSocket.bind("",7788)
    #等待接受对方发送的数据
    recvDate = udpSocket.recvfrom(1021) #1024表示本次接收的最大字节数
    #接收数据为元组: (数据,ip)
    content,destInfo = recvDate
    print("content is %s"%content.decode("utf-8"))
    # 显式接收的数据
    print(recvDate)
    #创建一个tcp套接字
    # tcpSocket = socket.socket(AF_INET,SOCK_STREAM)

    #udp套接字发送数据优化 解决第14行在数据前加b的问题(python3会出现)
    udpSocket = socket(AF_INET,SOCK_DGRAM)
    destIP = input("请输入目的ip:")
    destPort = int(input("请输入目的port:"))
    sendData = input("请输入要发送的数据:")
    udpSocket.sendto(sendData.encode("utf-8"),(destInfo,destPort))
  • 相关阅读:
    弹出窗口失败 Debug Assertion Failed!
    颜色设置 OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 的用法
    启动项
    进程PK线程
    获取代码运行时间,获取当前系统时间,日期
    在WindowsPhone8中生成基于MVVM Light的LongListSelector拼音检索绑定
    微软认证考试Mcts70511 part1翻译_Part2_使用控件_ContentControl
    微软认证考试Mcts70511 part1翻译_Part1_考分分配
    ORA14452: attempt to create, alter or drop an index on temporary table already in use
    HPUX日常工作整理
  • 原文地址:https://www.cnblogs.com/zhen1996/p/9100477.html
Copyright © 2011-2022 走看看