AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   HL2 UDP log, Python Class (https://forums.alliedmods.net/showthread.php?t=267125)

klausenbusk 07-23-2015 17:40

HL2 UDP log, Python Class
 
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



All times are GMT -4. The time now is 06:05.

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