Self-Improvement
[Python socket] Multicast Request/Receive 본문
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
from socket import *
# Multicast IP, Port
MCAST_GRP = '224.0.0.251'
MCAST_PORT = 5353
# UDP Socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
# on this port, receives ALL multicast groups
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', MCAST_PORT))
# Host IP Get
host = socket.gethostbyname(socket.gethostname())
# Multicast Request
sock.sendto("hello", (MCAST_GRP, MCAST_PORT))
# Multicast Receive setting
sock.setsockopt(socket.SOL_IP, socket.IP_ADD_MEMBERSHIP,socket.inet_aton(MCAST_GRP) + socket.inet_aton(host))
while 1:
print(sock.recv(1500))
|
cs |
'프로그래밍 > Python' 카테고리의 다른 글
파이썬 websocket(웹소켓) 사용법 예시 (0) | 2020.10.13 |
---|---|
python 유용한 정규식 표현 (0) | 2020.09.15 |
Python Requests 모듈의 HTTPS/HTTP 구분 (0) | 2020.07.16 |
Python의 Requests 모듈의 multipart/form-data(파일 전송) 형식 (0) | 2020.07.16 |
재미로 작성한 hsts bypass check Python 코드 (0) | 2020.03.18 |