Raised This Month: $51 Target: $400
 12% 

HL2 UDP log, Python Class


Post New Thread Reply   
 
Thread Tools Display Modes
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
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 11:10.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode