Skip to content

Commit 17ef2cb

Browse files
committed
Basic documentation
1 parent 2c5094b commit 17ef2cb

7 files changed

Lines changed: 115 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,4 @@ venv.bak/
103103
# mypy
104104
.mypy_cache/
105105
.idea
106+
*/.vscode*

docs/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ Welcome to RawSocketPy's documentation!
55
:maxdepth: 2
66
:caption: Contents:
77

8+
installation
9+
quicktest
10+
raw_socket
11+
server_mode
12+
813
Indices and tables
914
==================
1015

docs/installation.rst

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
Installation
2+
=======================================
3+
.. code-block:: bash
4+
:caption: installation
5+
:name: installation
6+
# using pypi
7+
sudo -H python -m pip install rawsocketpy
8+
9+
# for development
10+
git clone https://github.com/AlexisTM/rawsocket_python
11+
cd rawsocket_python
12+
sudo python pip . -e
13+
14+
# manually
15+
git clone https://github.com/AlexisTM/rawsocket_python
16+
sudo python setup.py install
17+
18+
19+
`gevent` is an optional dependency that allow concurrency for the RawServer.
20+
21+
You can install it using:
22+
23+
.. code-block:: bash
24+
:caption: installation
25+
:name: installation
26+
27+
sudo -H python -m pip install gevent
28+

docs/quicktest.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Quicktest
2+
=======================================
3+
4+
The simplest example to ensure the library is working for you is to take two machines (or one with two network cards) and run the following.
5+
6+
> Ensure to set **your interface** name instead of **wlp2s0**.
7+
8+
On the first machine:
9+
10+
.. code-block:: bash
11+
:caption: First machine
12+
:name: First machine
13+
14+
sudo python -c "from rawsocketpy import RawSocket
15+
sock = RawSocket('wlp2s0', 0xEEFA)
16+
while True: print(sock.recv())"
17+
18+
On the second machine:
19+
20+
.. code-block:: bash
21+
:caption: Second machine
22+
:name: Second machine
23+
24+
sudo python -c "from rawsocketpy import RawSocket; import time
25+
sock = RawSocket('wlp2s0', 0xEEFA)
26+
while True:
27+
sock.send('Boo')
28+
print('Boo has been sent')
29+
time.sleep(0.5)"
30+

docs/raw_socket.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Raw sockets
2+
============
3+
4+
The raw sockets is the base of the library.
5+
6+
7+

docs/server_mode.rst

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
Asynchronous Server with custom data handler
2+
==================
3+
4+
To a raw server, you have the following options:
5+
6+
* RawServer: Blocks for each message received until handled
7+
* RawServerCallback: Calls the callback and blocks until the callback returns
8+
* RawServerAsync: **if gevent available**, it will handle the incomming messages in a pool of Greenlets
9+
* RawServerAsyncCallback: **if gevent available**, it will add the callback in a pool of Greenlets
10+
11+
.. code-block:: python
12+
:caption: First machine
13+
:name: First machine
14+
15+
from rawsocketpy import RawRequestHandler, RawAsyncServerCallback
16+
import time
17+
18+
19+
def some_callback(handler, server):
20+
print("callback")
21+
handler.setup()
22+
handler.handle()
23+
handler.finish()
24+
25+
26+
class LongTaskTest(RawRequestHandler):
27+
def handle(self):
28+
time.sleep(1)
29+
print(self.packet)
30+
31+
def finish(self):
32+
print("End")
33+
34+
def setup(self):
35+
print("Begin")
36+
37+
38+
def main():
39+
rs = RawAsyncServerCallback("wlp2s0", 0xEEFA, LongTaskTest, some_callback)
40+
rs.spin()
41+
if __name__ == '__main__':
42+
main()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
long_description = fh.read()
55

66
setuptools.setup(name='rawsocketpy',
7-
version='0.2',
8-
description='This library allows you to implemnet a custom layer 2 communication using raw sockets in Python 2 and Python 3, synchronous and asynchronous, with and without callbacks.',
7+
version='0.2.1',
8+
description='This library allows you to implement a custom layer 2 communication using raw sockets in Python 2 and Python 3, synchronous and asynchronous, with and without callbacks.',
99
long_description=long_description,
1010
long_description_content_type="text/markdown",
1111
url='https://github.com/AlexisTM/rawsocket_python',

0 commit comments

Comments
 (0)