⇤ ← Revision 1 as of 2004-08-04 19:01:50
Size: 1081
Comment: How do you subscribe to a multicast address?
|
Size: 1150
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 23: | Line 23: |
sock.sendto( MESSAGE, (UDP_IP,_PORT) ) | sock.sendto( MESSAGE, (UDP_IP, UDP_PORT) ) |
Line 42: | Line 42: |
data, addr = sock.recvfrom( 1024 ) # what is 1024? "buf"..? | data, addr = sock.recvfrom( 1024 ) # buffer size is 1024 bytes |
Line 50: | Line 50: |
It is the buffer size.[[BR]] >>> help (sock.recvfrom) |
UDP Communication
Sending
Here's simple code to post a note by UDP in Python:
1 import socket
2
3 UDP_IP="127.0.0.1"
4 UDP_PORT=5005
5 MESSAGE="Hello, World!"
6
7 print "UDP target IP:", UDP_IP
8 print "UDP target port:", UDP_PORT
9 print "message:", MESSAGE
10
11 sock = socket.socket( socket.AF_INET, # Internet
12 socket.SOCK_DGRAM ) # UDP
13 sock.sendto( MESSAGE, (UDP_IP, UDP_PORT) )
Receiving
Here's simple code to receive UDP messages in Python:
Discussion
I have two questions:
- What is the 1024 in recvfrom?
It is the buffer size.BR >>> help (sock.recvfrom)
How do you subscribe to a Multicast_address ?
It seems that just setting UDP_IP to "224.0.0.250" (say) isn't quite good enough.