# 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**](https://github.com/emrecpp/PacketHandler/blob/main/ExampleUsage.py) 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**](https://github.com/emrecpp/PacketHandler/blob/main/ExampleUsage.py))
```
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"]
```
Raw data
{
"_id": null,
"home_page": "https://github.com/emrecpp/PacketHandler",
"name": "PacketHandler",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "Packet,socket,Handler,PacketHandler,Packet Handler,send,recv,serialize,serialization,deserialize,deserialization,compress,encrypt",
"author": "Emre Demircan",
"author_email": "emrecpp1@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/e6/60/588eae3503fd2719b991464069bbb11ce20a0e90ac7cf07c97bc312eb8fc/PacketHandler-1.0.9.2.tar.gz",
"platform": null,
"description": "# Python Packet Handler\r\nStore data as packet. Send, Recv, Encrypt and Compress it.\r\n\r\nYou will be able to manage **socket communication** easily and comprehensibly using this Python package.\r\nWith version 1.0.9 or later, you can use the \"**addListener**\" function to direct incoming opcodes to the desired function upon receipt.\r\n\r\nPlease refer to the [**Example Usage**](https://github.com/emrecpp/PacketHandler/blob/main/ExampleUsage.py) file for details and run it for demonstration.\r\n\r\n**These packages are also available for C# and C++ programming languages:**\r\n\r\nC#: https://github.com/emrecpp/DataPacket-CSharp\r\n\r\nC++: https://github.com/emrecpp/DataPacket-CPP\r\n## Installation\r\nYou can install **PacketHandler** using pip:\r\n\r\n```\r\npip install PacketHandler\r\n```\r\n\r\n# Usage ([**Detailed Usage**](https://github.com/emrecpp/PacketHandler/blob/main/ExampleUsage.py))\r\n\r\n```\r\nfrom Packet import Packet, ref\r\nimport sys, socket, select, time\r\n\r\nclass opcodes:\r\n LOGIN=100\r\n LOGOUT=101\r\n\r\nHOST, PORT = \"127.0.0.1\", 2000\r\n```\r\n# CLIENT\r\n```\r\nPaket = Packet(opcodes.LOGIN, Encrypt=True, Compress=True)\r\nUsername = \"Emre\"\r\nPaket << Username << \"123\" << True << bytearray(b'\\x07\\x10BYTES\\xFF') << [\"Apple\", \"Banana\", \"Orange\"]\r\nPaket.Send(socket)\r\n```\r\n# SERVER\r\n```\r\n# Listener Thread\r\nPaketListen = Packet()\r\nwhile True:\r\n if PaketListen.Recv(socketServer):\r\n PaketListen.Print(\"RECEIVED PACKET (YOUR TITLE)!\")\r\n if PacketListen.GetOpcode() == opcodes.LOGIN:\r\n UserName, Password, RememberMe, Data, Fruits = ref(str), ref(str), ref(bool), ref(bytearray), ref(list)\r\n PacketListen >> UserName >> Password >> RememberMe >> Data >> Fruits\r\n 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 ...)\r\n # Note: Can't use bool(RememberMe), this returns True everytime. Use .obj always !!!\r\n\r\n print(f\"Username: {UserName}\\nPassword: {Password}\\nRememberMe: {'Yes' if RememberMe else 'No'}\\nData: {str(Data)}\\nFruits: {Fruits}\")\r\n else:\r\n return # Connection Lost\r\n\r\n```\r\n\r\n# OUTPUT\r\n\r\n```\r\nUsername: Emre\r\nPassword: 123\r\nRememberMe: Yes\r\nData: bytearray(b'\\x07\\x10BYTES\\xff')\r\nFruits: Apple, Banana, Orange\r\n\r\n\r\n*** RECEIVED PACKET (YOUR TITLE)! *** (67)\r\n00000000: 00 64 02 06 00 00 04 00 00 00 45 6D 72 65 03 00 .d........Emre..\r\n00000010: 00 00 31 32 33 01 08 00 00 00 07 10 42 59 54 45 ..123.......BYTE\r\n00000020: 53 FF 1D 00 00 00 5B 22 41 70 70 6C 65 22 2C 20 S.\u00c3\u00bf.........[.\".A.p.p.l.e.\".,..\r\n00000030: 22 42 61 6E 61 6E 61 22 2C 20 22 4F 72 61 6E 67 \"Banana\",.\"Orang\r\n00000040: 65 22 5D e\"]\r\n\r\n```\r\n\r\n",
"bugtrack_url": null,
"license": "GPL",
"summary": "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.",
"version": "1.0.9.2",
"project_urls": {
"Download": "https://pypi.org/project/PacketHandler/",
"Homepage": "https://github.com/emrecpp/PacketHandler"
},
"split_keywords": [
"packet",
"socket",
"handler",
"packethandler",
"packet handler",
"send",
"recv",
"serialize",
"serialization",
"deserialize",
"deserialization",
"compress",
"encrypt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7d9c45a586a1f514670f64ce1118f5ae78c4f4c79a952d4205b33289446b053d",
"md5": "2773aadcd79317612508978f533d024e",
"sha256": "8ea5e75aa8679a92b2bfceef3b0dec2d13ff98e555dc434cf4a2bd37dc23cba3"
},
"downloads": -1,
"filename": "PacketHandler-1.0.9.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2773aadcd79317612508978f533d024e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 23846,
"upload_time": "2023-08-06T15:02:41",
"upload_time_iso_8601": "2023-08-06T15:02:41.743689Z",
"url": "https://files.pythonhosted.org/packages/7d/9c/45a586a1f514670f64ce1118f5ae78c4f4c79a952d4205b33289446b053d/PacketHandler-1.0.9.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e660588eae3503fd2719b991464069bbb11ce20a0e90ac7cf07c97bc312eb8fc",
"md5": "0554ba07ea0bd1eb6fe15c44d81fe5e3",
"sha256": "9cb14395b0ba91132e2c5ea6c179e5ad65c3f81fceef6923704ecaae5f5acff9"
},
"downloads": -1,
"filename": "PacketHandler-1.0.9.2.tar.gz",
"has_sig": false,
"md5_digest": "0554ba07ea0bd1eb6fe15c44d81fe5e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 22393,
"upload_time": "2023-08-06T15:02:43",
"upload_time_iso_8601": "2023-08-06T15:02:43.477794Z",
"url": "https://files.pythonhosted.org/packages/e6/60/588eae3503fd2719b991464069bbb11ce20a0e90ac7cf07c97bc312eb8fc/PacketHandler-1.0.9.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-06 15:02:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "emrecpp",
"github_project": "PacketHandler",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "packethandler"
}