A class I just did.
I let the code do the explanation..
PHP Code:
import socket
class hl2udplog():
def __init__(self, port, host="", remoteHost="", remotePort=""):
self.s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.s.bind((host, port))
self.remoteHost = remoteHost
self.remotePort = remotePort
self.checkHost = remoteHost != ""
self.checkPort = remotePort != ""
def start(self, function):
while 1:
package = self.s.recvfrom(4096)
if 5 < len(package[0]) and (not self.checkHost or self.remoteHost == package[1][0]) and (not self.checkPort or self.remotePort == package[1][1]):
function(package[0][5:].rstrip("\n\x00"))
Example:
PHP Code:
def test(message):
print "Incomming log message!!!"
print message
hu = hl2udplog(8888, remoteHost="92.222.66.197", remotePort="27030")
hu.start(test)