PSE Entertainment Corp
May 21, 2012, 01:46:31 AM
Welcome,
Guest
. Please
login
or
register
.
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
News
: Enjoy PSE Tunes! They're great!
Home
Help
Search
Login
Register
PSE Entertainment Corp
>
Development
>
Python
>
Python UDP Packet Splitter
Pages: [
1
]
« previous
next »
Print
Author
Topic: Python UDP Packet Splitter (Read 2283 times)
webmast
Guest
Python UDP Packet Splitter
«
on:
April 09, 2008, 06:23:53 PM »
If you've ever needed a method to accept a udp packet of ascii data and split it to a number of other locations, here's a quick and easy Python method:
>>>>>>>>>>>>>>>>>>>>>>>>
import socket
##Create a socket for the inbound UDP packets that we'd like to split.
s_in = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s_in.bind(('127.0.0.1',6000))
print "Listening on: %s" % repr(s_in.getsockname())
##Create a socket for the outbound destinations we'd like
##to send the split UDP packets to.
s_out = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
##Here's a list of destination IP's and Ports - this list can go on and on...
destination_list = [('127.0.0.1',10000),('127.0.0.1',10001)]
##Infinite loop to listen and split the data
while 1:
data,addr = s_in.recvfrom(1024)
if not data:break
else:
for destination in destination_list:
s_out.connect(destination)
s_out.send(data)
print "%s sent to : %s" % (data,destination)
«
Last Edit: May 27, 2010, 09:02:24 AM by webmaster
»
Report to moderator
Logged
Pages: [
1
]
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
General Category
-----------------------------
=> PSE Discussion Forum
-----------------------------
Development
-----------------------------
=> Python
Loading...