protlib | Easily implement binary network protocols | Reflection library
kandi X-RAY | protlib Summary
kandi X-RAY | protlib Summary
protlib makes it easy to implement binary network protocols. It uses the struct and SocketServer modules from the standard library. It provides support for default and constant struct fields, nested structs, arrays of structs, better handling for strings and arrays, struct inheritance, and convenient syntax for instantiating and using your custom structs. protlib supports Python 2.6 and 2.7 as well as Python 3.2 and later. protlib is free for use under the BSD license. See the LICENSE.txt file in this directory for details. Full documentation for protlib can be found in the docs/ folder or online at
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse a binary file into a struct
- Return a hexadecimal representation of the data
- Log incoming data
- Log a message
- Read data from the server
- Check if the given socket is open
- Handle incoming requests
- Underscore camelcased case
- Dispatch the given data
- Handle raw data
- Log data and write to f
- Return a CC response
- Return the zip code for the given SSN
- Logs a message
- Return a serialized representation of the object
- Returns a CStructType instance
- Return a tuple of hashable fields
- Returns all the fields of a CStruct class
- Log a raw message
protlib Key Features
protlib Examples and Code Snippets
Community Discussions
Trending Discussions on protlib
QUESTION
I am trying to send binary data to a server that gives me back a response on doing so. The rules seems understandable to someone who is familiar with python but I am new to python and socket programming using struct. So the documentation states this:
There is an 8 byte header that has a 32 bit integer for the request tag and a 32 bit integer for the command. The type is uint32. The buffersize depends on the type of command.
Some commands take arguments and they are sent in tandem with the command message header directly after the header with no padding. The size of the arguments buffer is dictated by the command type.
So I connected to the server and now I tried to package to values and send it like that but I dont know if I am doing it right.
...ANSWER
Answered 2019-Sep-16 at 18:14Ok so I found the errror and was able to get the response I wanted with the server. The error was with
packer = struct.Struct('i i ') // Needed to format it like ('! i i')
and raw_data = sock.recv(1024) unpacked_data = struct.unpack('>i i', raw_data) // Needed to add ! not > print(unpacked_data) sock.close()
also I wrote a simple unpacker that helped me to unpack it the proper way
def data_unpacking(data): tag, code = struct.unpack('!ii', data[:8]) return tag, code, data[8:]
then called the function in main with the parameter raw_data
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install protlib
You can use protlib like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page