Skip to content

Commit eefba41

Browse files
author
zhen.guo
committed
add uwebsocket use and uping-(ICMP)ping by Jaxsen Xu
1 parent c09370c commit eefba41

File tree

4 files changed

+325
-0
lines changed

4 files changed

+325
-0
lines changed

en-us/api/QuecPythonClasslib.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12467,3 +12467,64 @@ if __name__ == '__main__':
1246712467

1246812468
```
1246912469

12470+
12471+
12472+
#### uping-(ICMP)ping包
12473+
12474+
Module function: Simulate sending icmp-ping packets
12475+
12476+
12477+
12478+
##### ping
12479+
12480+
- Precautions
12481+
12482+
There may be exceptions here, because the host address cannot resume the exception of the socket connection
12483+
12484+
Periodically send Ping packet mechanism through `COUNT` and `INTERVAL` in initialization parameters
12485+
12486+
> **import uping**
12487+
>
12488+
> **up = uping.ping(HOST, SOURCE=None, COUNT=4, INTERVAL=1000, SIZE=64, TIMEOUT=5000, quiet=False)**
12489+
12490+
- parameter
12491+
12492+
| parameter | type | illustrate |
12493+
| --------- | ---- | ------------------------------------------------------------ |
12494+
| HOST | str | The domain name address to be pinged, such as "baidu.com" |
12495+
| SOURCE | str | Source address, used for binding, generally does not need to be passed |
12496+
| COUNT | int | The default is 4 times, send 4 ping packets |
12497+
| INTERVAL | int | Interval time, the default is ms, the default is 1000ms |
12498+
| SIZE | int | The default packet size of each read is 64, no need to modify |
12499+
| TIMEOUT | int | Timeout time, the unit is ms, the default is 5000ms or 5s |
12500+
| quiet | bool | Default fasle, print output, after setting True, the printed value obtained after calling start will be converted into an object and returned, rather than displayed by printing |
12501+
12502+
12503+
12504+
example of use
12505+
12506+
```python
12507+
# method one
12508+
# printout method
12509+
import uping
12510+
uping.ping('baidu.com')
12511+
12512+
# The following is the output of uping.start(), no return value
12513+
#72 bytes from 49.49.48.46: icmp_seq=1, ttl=53, time=1169.909000 ms
12514+
#72 bytes from 49.49.48.46: icmp_seq=2, ttl=53, time=92.060000 ms
12515+
#72 bytes from 49.49.48.46: icmp_seq=3, ttl=53, time=94.818000 ms
12516+
#72 bytes from 49.49.48.46: icmp_seq=4, ttl=53, time=114.879000 ms
12517+
#4 packets transmitted, 4 packets received, 0 packet loss
12518+
#round-trip min/avg/max = 92.06000000000001/367.916/1169.909 ms
12519+
12520+
12521+
12522+
12523+
# Method 2
12524+
# Setting quiet will get the output
12525+
import uping
12526+
result = uping.ping('baidu.com', quiet=True)
12527+
# result can get the corresponding data
12528+
# result(tx=4, rx=4, losses=0, min=76.93899999999999, avg=131.348, max=226.697)
12529+
```
12530+

en-us/api/QuecPythonThirdlib.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,6 +2248,108 @@ sys_bus.unsubscribe("test")
22482248

22492249

22502250

2251+
#### uwebsocket use
2252+
2253+
Module: Mainly used for websocket connection use
2254+
2255+
2256+
2257+
##### Client connection
2258+
2259+
> **import uwebsocket**
2260+
>
2261+
> **ws_client = uwebsocket.Client.connect(uri, headers=None, debug=False)**
2262+
2263+
- paramter
2264+
2265+
| parameter | type | illustrate |
2266+
| --------- | ---- | ------------------------------------------------------------ |
2267+
| uri | str | The connection address of websocket, generally exists in the form of "ws://xxx/" or "wss://xxx/" |
2268+
| headers | dict | Additional headers that need to be added are used to allow users to pass additional headers in addition to the standard headers |
2269+
| debug | bool | The default is False, when it is True, the log will be output |
2270+
2271+
2272+
2273+
##### send data
2274+
2275+
> **ws_client.send(msg)**
2276+
2277+
- paramter
2278+
2279+
| parameter | type | illustrate |
2280+
| --------- | ---- | ------------ |
2281+
| msg | str | data to send |
2282+
2283+
- return value
2284+
2285+
None
2286+
2287+
2288+
2289+
##### recv data
2290+
2291+
> **ws_client.recv()**
2292+
2293+
- paramter
2294+
2295+
None
2296+
2297+
- return value
2298+
2299+
| return value | type | illustrate |
2300+
| ------------ | ---- | ------------------------------------------------------------ |
2301+
| result | str | The returned result is the result of recv. When a null value or None is accepted, the connection is closed. |
2302+
2303+
2304+
2305+
##### close connect
2306+
2307+
> **ws_client.close()**
2308+
2309+
- paramter
2310+
2311+
None
2312+
2313+
- return Value
2314+
2315+
None
2316+
2317+
2318+
2319+
##### Example of use
2320+
2321+
```python
2322+
from usr import uwebsocket
2323+
import _thread
2324+
2325+
2326+
def recv(cli):
2327+
while True:
2328+
# Infinite loop to receive data
2329+
recv_data = cli.recv()
2330+
print("recv_data = {}".format(recv_data))
2331+
if not recv_data:
2332+
# The server closes the connection or the client closes the connection
2333+
print("cli close")
2334+
client.close()
2335+
break
2336+
2337+
2338+
# Create a client, debug=True to output logs, ip and port need to be filled in by yourself, or a domain name
2339+
client = uwebsocket.Client.connect('ws://xxx/', debug=True)
2340+
2341+
# Thread receives data
2342+
_thread.start_new_thread(recv, (client,))
2343+
2344+
# send data
2345+
client.send("this is a test msg")
2346+
2347+
```
2348+
2349+
2350+
2351+
2352+
22512353
#### ussl-SSL Algorithm
22522354
Note: The BC25PA platform does not support this module function.
22532355

zh-cn/api/QuecPythonClasslib.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12905,3 +12905,63 @@ if __name__ == '__main__':
1290512905

1290612906
```
1290712907

12908+
12909+
12910+
#### uping-(ICMP)ping包
12911+
12912+
模块功能: 模拟发送icmp-ping包
12913+
12914+
12915+
12916+
##### ping
12917+
12918+
- 注意事项
12919+
12920+
这里可能会存在异常, 由于host地址无法简历socket连接的异常
12921+
12922+
通过初始化参数中的`COUNT``INTERVAL`来周期性的发送Ping包机制
12923+
12924+
> **import uping**
12925+
>
12926+
> **up = uping.ping(HOST, SOURCE=None, COUNT=4, INTERVAL=1000, SIZE=64, TIMEOUT=5000, quiet=False)**
12927+
12928+
- 参数
12929+
12930+
| 参数 | 类型 | 说明 |
12931+
| -------- | ---- | ------------------------------------------------------------ |
12932+
| HOST | str | 所要ping的域名地址, 例如"baidu.com" |
12933+
| SOURCE | str | 源地址, 用于绑定, 一般情况下不需要传 |
12934+
| COUNT | int | 默认是4次, 发送4次ping包 |
12935+
| INTERVAL | int | 间隔时间, 默认是ms单位, 默认1000ms |
12936+
| SIZE | int | 每次读取的包大小默认64, 无需修改 |
12937+
| TIMEOUT | int | 超时时间, 单位是ms单位, 默认是5000ms5s |
12938+
| quiet | bool | 默认fasle,打印输出, 设置True后, 调用start的后得到的打印的值会被转换成对象返回, 而不是通过打印显示 |
12939+
12940+
使用示例
12941+
12942+
```python
12943+
# 方式一
12944+
# 打印输出方式
12945+
import uping
12946+
uping.ping('baidu.com')
12947+
12948+
# 以下是uping.start()的输出, 无返回值
12949+
#72 bytes from 49.49.48.46: icmp_seq=1, ttl=53, time=1169.909000 ms
12950+
#72 bytes from 49.49.48.46: icmp_seq=2, ttl=53, time=92.060000 ms
12951+
#72 bytes from 49.49.48.46: icmp_seq=3, ttl=53, time=94.818000 ms
12952+
#72 bytes from 49.49.48.46: icmp_seq=4, ttl=53, time=114.879000 ms
12953+
#4 packets transmitted, 4 packets received, 0 packet loss
12954+
#round-trip min/avg/max = 92.06000000000001/367.916/1169.909 ms
12955+
12956+
12957+
12958+
12959+
# 方式二
12960+
# 设置quiet会得到输出结果
12961+
import uping
12962+
result = uping.ping('baidu.com', quiet=True)
12963+
# result可以拿到对应数据
12964+
# result(tx=4, rx=4, losses=0, min=76.93899999999999, avg=131.348, max=226.697)
12965+
12966+
```
12967+

zh-cn/api/QuecPythonThirdlib.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,6 +2270,108 @@ sys_bus.unsubscribe("test")
22702270
[uasyncio文档中心](https://python.quectel.com/doc/doc/Advanced_development/zh/QuecPythonThird/asyncio.html)
22712271

22722272

2273+
2274+
#### uwebsocket使用
2275+
2276+
模块: 主要用于websocket连接使用
2277+
2278+
2279+
2280+
##### 客户端连接
2281+
2282+
> **import uwebsocket**
2283+
>
2284+
> **ws_client = uwebsocket.Client.connect(uri, headers=None, debug=False)**
2285+
2286+
- 参数
2287+
2288+
| 参数 | 类型 | 说明 |
2289+
| ------- | ---- | ------------------------------------------------------------ |
2290+
| uri | str | websocket的连接地址, 一般以"ws://xxx/"或"wss://xxx/"形式存在 |
2291+
| headers | dict | 额外需要添加的headers, 用于除了标准连接头之外, 允许用户自己传额外的头部 |
2292+
| debug | bool | 默认False, 当为True的情况下, 会输出日志 |
2293+
2294+
2295+
2296+
##### send发送数据
2297+
2298+
> **ws_client.send(msg)**
2299+
2300+
- 参数
2301+
2302+
| 参数 | 类型 | 说明 |
2303+
| ---- | ---- | -------------- |
2304+
| msg | str | 需要发送的数据 |
2305+
2306+
- 返回值
2307+
2308+
2309+
2310+
2311+
2312+
##### recv接收数据
2313+
2314+
> **ws_client.recv()**
2315+
2316+
- 参数
2317+
2318+
2319+
2320+
- 返回值
2321+
2322+
| 返回值 | 类型 | 说明 |
2323+
| ------ | ---- | ------------------------------------------------------------ |
2324+
| result | str | 返回的结果, 就是recv的结果, 当接受空值或None的时候, 为连接被关闭 |
2325+
2326+
2327+
2328+
##### 关闭连接
2329+
2330+
> **ws_client.close()**
2331+
2332+
- 参数
2333+
2334+
2335+
2336+
- 返回值
2337+
2338+
2339+
2340+
2341+
2342+
##### 使用示例
2343+
2344+
```python
2345+
from usr import uwebsocket
2346+
import _thread
2347+
2348+
2349+
def recv(cli):
2350+
while True:
2351+
# 死循环接收数据
2352+
recv_data = cli.recv()
2353+
print("recv_data = {}".format(recv_data))
2354+
if not recv_data:
2355+
# 服务器关闭连接或客户端关闭连接
2356+
print("cli close")
2357+
client.close()
2358+
break
2359+
2360+
2361+
# 创建客户端, debug=True输出日志, ip和端口需要自己填写, 或者是域名
2362+
client = uwebsocket.Client.connect('ws://xxx/', debug=True)
2363+
2364+
# 线程接收数据
2365+
_thread.start_new_thread(recv, (client,))
2366+
2367+
# 发送数据
2368+
client.send("this is a test msg")
2369+
2370+
```
2371+
2372+
2373+
2374+
22732375
#### ussl-SSL算法
22742376

22752377
* 注意

0 commit comments

Comments
 (0)