Skip to content

Commit 69f1981

Browse files
author
jczic
committed
update all...
1 parent 42534d7 commit 69f1981

File tree

6 files changed

+162
-3
lines changed

6 files changed

+162
-3
lines changed

LICENSE.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
The MIT License (MIT)
2+
Copyright © 2018 Jean-Christophe Bos & HC² (www.hc2.fr)
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5+
6+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7+
8+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
## XAsyncSockets is a little but full library of managed asynchronous sockets.
2+
3+
![HC²](hc2.png "HC²")
4+
5+
#### Very easy to integrate and very light with one file only :
6+
- `"XAsyncSockets.py"`
7+
8+
#### XAsyncSockets features :
9+
- Managed asynchronous sockets (in pool)
10+
- Works directly with I/O
11+
- Support for a very large number of simultaneous connections
12+
- Support for concurrent processing (threaded)
13+
- Implementation of TCP server
14+
- Implementation of TCP client
15+
- Implementation of UDP datagrams sender/receiver
16+
- Really robust and very fast
17+
- Easy to use
18+
19+
### *XAsyncSockets* classes :
20+
21+
| Class name | Description |
22+
| - | - |
23+
| XAsyncSocketsPool | Managed pool of 'XAsyncSocket' objects |
24+
| XClosedReason | Enumerator of 'XAsyncSocket' closing reasons |
25+
| XAsyncSocket | Abstract class of managed asynchronous sockets |
26+
| XAsyncTCPServer | TCP server implementation of 'XAsyncSocket' |
27+
| XAsyncTCPClient | TCP client implementation of 'XAsyncSocket' |
28+
| XAsyncUDPDatagram | UDP sender/recever implementation of 'XAsyncSocket' |
29+
| XBufferSlot | Managed buffer |
30+
| XBufferSlots | Managed buffers collection |
31+
32+
### *XAsyncSockets* exceptions :
33+
34+
| Class name | Description |
35+
| - | - |
36+
| XAsyncSocketsPoolException | Exception class for 'XAsyncSocketsPool' |
37+
| XAsyncSocketException | Exception class for 'XAsyncSocket' |
38+
| XAsyncTCPServerException | Exception class for 'XAsyncTCPServer' |
39+
| XAsyncTCPClientException | Exception class for 'XAsyncTCPClient' |
40+
| XAsyncUDPDatagramException | Exception class for 'XAsyncUDPDatagram' |
41+
42+
### *XAsyncSocketsPool* class details :
43+
44+
| Method | Arguments |
45+
| - | - |
46+
| Constructor | None |
47+
| AsyncWaitEvents | `threadsCount=0` (int) |
48+
| StopWaitEvents | None |
49+
50+
( Do not call directly the methods `AddAsyncSocket`, `RemoveAsyncSocket`, `NotifyNextReadyForReading` and `NotifyNextReadyForWriting` )
51+
52+
### *XClosedReason* class details :
53+
54+
| Static variable | Value |
55+
| - | - |
56+
| Error | 0x00 |
57+
| ClosedByHost | 0x01 |
58+
| ClosedByPeer | 0x02 |
59+
| Timeout | 0x03 |
60+
61+
### *XAsyncSocket* class details :
62+
63+
| Method | Arguments |
64+
| - | - |
65+
| GetAsyncSocketsPool | None |
66+
| GetSocketObj | None |
67+
| Close | None |
68+
69+
| Property | Details |
70+
| - | - | - |
71+
| OnClosed | Get or set an event of type f(closedReason) |
72+
| State | Get or set object |
73+
74+
### *XAsyncTCPServer* class details :
75+
76+
| Method | Arguments |
77+
| - | - |
78+
| Create (static) | `asyncSocketsPool`, `srvAddr` (tuple of ip and port), `srvBacklog=256` (int), `recvBufSlots=None` |
79+
80+
| Property | Details |
81+
| - | - | - |
82+
| SrvAddr | Tuple of ip and port |
83+
| OnClientAccepted | Get or set an event of type f(xAsyncTCPServer, xAsyncTCPClient) |
84+
85+
### *XAsyncTCPClient* class details :
86+
87+
| Method | Arguments |
88+
| - | - |
89+
| Create (static) | `asyncSocketsPool`, `srvAddr`, `connectTimeout=5`(int), `recvbufLen=4096`(int) |
90+
| AsyncRecvLine | `timeoutSec=None` (int) |
91+
| AsyncRecvData | `size=None` (int), `timeoutSec=None` (int) |
92+
| AsyncSendData | `data` (bytes or buffer protocol) |
93+
94+
| Property | Details |
95+
| - | - | - |
96+
| SrvAddr | Tuple of ip and port |
97+
| CliAddr | Tuple of ip and port |
98+
| OnFailsToConnect | Get or set an event of type f(xAsyncTCPClient) |
99+
| OnConnected | Get or set an event of type f(xAsyncTCPClient) |
100+
| OnLineRecv | Get or set an event of type f(xAsyncTCPClient, line) |
101+
| OnDataRecv | Get or set an event of type f(xAsyncTCPClient, data) |
102+
| OnCanSend | Get or set an event of type f(xAsyncTCPClient) |
103+
104+
### *XAsyncUDPDatagram* class details :
105+
106+
| Method | Arguments |
107+
| - | - |
108+
| Create (static) | `asyncSocketsPool`, `localAddr=None` (tuple of ip and port), `recvbufLen=4096`(int), `broadcast=False`(bool) |
109+
| AsyncSendDatagram | `datagram` (bytes or buffer protocol), `remoteAddr` (tuple of ip and port) |
110+
111+
| Property | Details |
112+
| - | - | - |
113+
| LocalAddr | Tuple of ip and port |
114+
| OnRecv | Get or set an event of type f(xAsyncUDPDatagram, remoteAddr, datagram) |
115+
| OnFailsToSend | Get or set an event of type f(xAsyncUDPDatagram, datagram, remoteAddr) |
116+
| OnCanSend | Get or set an event of type f(xAsyncUDPDatagram) |
117+
118+
### *XBufferSlot* class details :
119+
120+
| Method | Arguments |
121+
| - | - |
122+
| Constructor | `size` (int), `keepAlloc=True`(bool) |
123+
124+
| Property | Details |
125+
| - | - | - |
126+
| Available | Get or set the availability of the slot |
127+
| Size | Get the buffer size of the slot |
128+
| Buffer | Get the buffer of the slot |
129+
130+
### *XBufferSlots* class details :
131+
132+
| Method | Arguments |
133+
| - | - |
134+
| Constructor | `slotsCount`(int), `slotsSize`(int), `keepAlloc=True`(bool) |
135+
| GetAvailableSlot | None |
136+
137+
| Property | Details |
138+
| - | - | - |
139+
| SlotsCount | Get the number of slots |
140+
| SlotsSize | Get the buffer size of each slots |
141+
| Slots | Get the list of slots |
142+
143+
### By JC`zic for [HC²](https://www.hc2.fr) ;')
144+
145+
*Keep it simple, stupid* :+1:

XAsyncSockets.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
"""
2+
The MIT License (MIT)
3+
Copyright © 2018 Jean-Christophe Bos & HC² (www.hc2.fr)
4+
"""
5+
16

2-
from select import select
3-
from time import perf_counter, sleep
47
from _thread import allocate_lock, start_new_thread
8+
from time import perf_counter, sleep
9+
from select import select
510
from queue import Queue
611
import socket
712

_config.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-midnight

hc2.png

23.2 KB
Loading

udpRecv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import XAsyncSockets
22

3-
def _onUDPDatagramRecv(XAsyncUDPDatagram, remoteAddr, datagram) :
3+
def _onUDPDatagramRecv(xAsyncUDPDatagram, remoteAddr, datagram) :
44
print('On UDP Datagram Recv (%s:%s) :' % remoteAddr)
55
print(datagram.tobytes())
66

0 commit comments

Comments
 (0)