added packet.py and the Packet class
This commit is contained in:
parent
a5c47f72ef
commit
1102e075c0
36
pypong/networking/packet.py
Normal file
36
pypong/networking/packet.py
Normal file
@ -0,0 +1,36 @@
|
||||
"""
|
||||
Contains the Packet class to help with the transmission, reading, and verification of infermation over the network
|
||||
"""
|
||||
|
||||
|
||||
class Packet:
|
||||
"""
|
||||
Class that contains information to be sent over the network. Can self-verify and has methods (will have methods) to
|
||||
easily encode and decode packet information
|
||||
"""
|
||||
VALID_HEADERS = [
|
||||
'PYPONGREQ',
|
||||
'PYPONGRST'
|
||||
]
|
||||
VALID_TYPES = [
|
||||
'SVRINFO'
|
||||
]
|
||||
|
||||
def __init__(self, header, msg_type, *message):
|
||||
self.header = header
|
||||
self.msg_type = msg_type
|
||||
self.message = []
|
||||
for x in message:
|
||||
self.message.append(x)
|
||||
|
||||
def integrity_check(self):
|
||||
"""
|
||||
Verify that the information in the packet is correct and makes sense
|
||||
|
||||
:return: True if packet verifies correctly, False if not
|
||||
"""
|
||||
if self.header not in Packet.VALID_HEADERS:
|
||||
return False
|
||||
if self.msg_type not in Packet.VALID_TYPES:
|
||||
return False
|
||||
return True
|
Loading…
Reference in New Issue
Block a user