1081
Comment: How do you subscribe to a multicast address?
|
1537
|
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) |
|
Line 53: | Line 55: |
* It would seem easy to extend this to a simple means to open a file on the sender side, send datagrams to the receiver side, and write those packets to a file there - I just wonder about synchronisation issues regarding the buffer...Anyone smart care to put something down, say as a simple practical extension of what is already here? (And if you do it pls delete this message) * |
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.
* It would seem easy to extend this to a simple means to open a file on the sender side, send datagrams to the receiver side, and write those packets to a file there - I just wonder about synchronisation issues regarding the buffer...Anyone smart care to put something down, say as a simple practical extension of what is already here? (And if you do it pls delete this message) *