Skip to main content

Store data as packet. Send, Recv, Encrypt and Compress it. You will be able to manage **socket communication** easily and comprehensibly using this Python package.

Project description

Python Packet Handler

Store data as packet. Send, Recv, Encrypt and Compress it.

You will be able to manage socket communication easily and comprehensibly using this Python package. With version 1.0.9 or later, you can use the "addListener" function to direct incoming opcodes to the desired function upon receipt.

Please refer to the Example Usage file for details and run it for demonstration.

These packages are also available for C# and C++ programming languages:

C#: https://github.com/emrecpp/DataPacket-CSharp

C++: https://github.com/emrecpp/DataPacket-CPP

Installation

You can install PacketHandler using pip:

pip install PacketHandler

Usage (Detailed Usage)

from Packet import Packet, ref
import sys, socket, select, time

class opcodes:
    LOGIN=100
    LOGOUT=101

HOST, PORT = "127.0.0.1", 2000

CLIENT

Paket = Packet(opcodes.LOGIN, Encrypt=True, Compress=True)
Username = "Emre"
Paket << Username << "123" << True << bytearray(b'\x07\x10BYTES\xFF') << ["Apple", "Banana", "Orange"]
Paket.Send(socket)

SERVER

# Listener Thread
PaketListen = Packet()
while True:
    if PaketListen.Recv(socketServer):
        PaketListen.Print("RECEIVED PACKET (YOUR TITLE)!")
        if PacketListen.GetOpcode() == opcodes.LOGIN:
            UserName, Password, RememberMe, Data, Fruits = ref(str), ref(str), ref(bool), ref(bytearray), ref(list)
            PacketListen >> UserName >> Password >> RememberMe >> Data >> Fruits
            UserName, Password, RememberMe, Data, Fruits = str(UserName), str(Password), RememberMe.obj, bytearray(Data.obj), ", ".join(Fruits.obj)  # We have to cast ref object to (int, str, bool, bytearray ...)
            # Note: Can't use bool(RememberMe), this returns True everytime. Use .obj always !!!

            print(f"Username: {UserName}\nPassword: {Password}\nRememberMe: {'Yes' if RememberMe else 'No'}\nData: {str(Data)}\nFruits: {Fruits}")
    else:
        return # Connection Lost

OUTPUT

Username: Emre
Password: 123
RememberMe: Yes
Data: bytearray(b'\x07\x10BYTES\xff')
Fruits: Apple, Banana, Orange


*** RECEIVED PACKET (YOUR TITLE)! *** (67)
00000000: 00 64 02 06 00 00 04 00 00 00 45 6D 72 65 03 00   .d........Emre..
00000010: 00 00 31 32 33 01 08 00 00 00 07 10 42 59 54 45   ..123.......BYTE
00000020: 53 FF 1D 00 00 00 5B 22 41 70 70 6C 65 22 2C 20   S.ÿ.........[.".A.p.p.l.e.".,..
00000030: 22 42 61 6E 61 6E 61 22 2C 20 22 4F 72 61 6E 67   "Banana",."Orang
00000040: 65 22 5D                                           e"]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PacketHandler-1.0.9.2.tar.gz (22.4 kB view details)

Uploaded Source

Built Distribution

PacketHandler-1.0.9.2-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file PacketHandler-1.0.9.2.tar.gz.

File metadata

  • Download URL: PacketHandler-1.0.9.2.tar.gz
  • Upload date:
  • Size: 22.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for PacketHandler-1.0.9.2.tar.gz
Algorithm Hash digest
SHA256 9cb14395b0ba91132e2c5ea6c179e5ad65c3f81fceef6923704ecaae5f5acff9
MD5 0554ba07ea0bd1eb6fe15c44d81fe5e3
BLAKE2b-256 e660588eae3503fd2719b991464069bbb11ce20a0e90ac7cf07c97bc312eb8fc

See more details on using hashes here.

File details

Details for the file PacketHandler-1.0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for PacketHandler-1.0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ea5e75aa8679a92b2bfceef3b0dec2d13ff98e555dc434cf4a2bd37dc23cba3
MD5 2773aadcd79317612508978f533d024e
BLAKE2b-256 7d9c45a586a1f514670f64ce1118f5ae78c4f4c79a952d4205b33289446b053d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page