View Single Post
Author Message
klausenbusk
AlliedModders Donor
Join Date: Jan 2011
Old 07-23-2015 , 17:40   HL2 UDP log, Python Class
Reply With Quote #1

A class I just did.
I let the code do the explanation..
PHP Code:
import socket

class hl2udplog():
    
def __init__(selfporthost=""remoteHost=""remotePort=""):
        
self.socket.socket(socket.AF_INETsocket.SOCK_DGRAM)
        
self.s.bind((hostport))
        
self.remoteHost remoteHost
        self
.remotePort remotePort
        self
.checkHost remoteHost != ""
        
self.checkPort remotePort != ""

    
def start(self, function):
        while 
1:
            
package self.s.recvfrom(4096)
            if 
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(8888remoteHost="92.222.66.197"remotePort="27030")

hu.start(test

Last edited by klausenbusk; 07-23-2015 at 18:12.
klausenbusk is offline