LoginSignup
2
2

More than 5 years have passed since last update.

PythonでUDPパケット送ってみた

Last updated at Posted at 2018-08-29

概要

UDPパケット飛ばしたい!

環境

  • 送信側

    • OS : Windows10 Pro
    • IDE : PyCharm CE
    • Python3.6
  • 受信側

ソース

1~100までを0.3sごとに飛ばすだけ

udp_send.py
# -*-coding:utf-8 -*-

import socket
import time

raw_msg = 1
# 送るメッセージ

s_ip = "192.168.1.3"
s_port = 9998
# アドレス・ポート

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

while raw_msg <= 100:
    msg = str(raw_msg)
    client.sendto(msg.encode(), (s_ip, s_port))
    print(raw_msg)
    raw_msg += 1
    time.sleep(0.3)


送れるのはbytes型だけ

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2