mirror of
https://github.com/SantaSpeen/winConnect.git
synced 2026-04-13 19:36:05 +00:00
[+] add examples
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
from winConnect import WinConnectClient
|
||||
|
||||
connector = WinConnectClient('test')
|
||||
|
||||
for data in connector.listen():
|
||||
print(data)
|
||||
i = input(":> ")
|
||||
connector.send_data(i)
|
||||
16
examples/client_console.py
Normal file
16
examples/client_console.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from winConnect import WinConnectClient
|
||||
|
||||
connector = WinConnectClient('test')
|
||||
|
||||
def console():
|
||||
with connector as conn:
|
||||
while True:
|
||||
i = input(":> ")
|
||||
if i == "exit":
|
||||
break
|
||||
conn.send_data(i)
|
||||
data = conn.read_pipe()
|
||||
print(f"({type(data)}) {data=}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
console()
|
||||
17
examples/client_console_handled.py
Normal file
17
examples/client_console_handled.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from winConnect import WinConnectClient
|
||||
|
||||
connector = WinConnectClient('test')
|
||||
|
||||
def console():
|
||||
conn = connector.connect()
|
||||
while True:
|
||||
i = input(":> ")
|
||||
if i == "exit":
|
||||
break
|
||||
conn.send_data(i)
|
||||
data = conn.read_pipe()
|
||||
print(f"({type(data)}) {data=}")
|
||||
conn.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
console()
|
||||
21
examples/client_test_dataclass.py
Normal file
21
examples/client_test_dataclass.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from winConnect import WinConnectClient
|
||||
|
||||
connector = WinConnectClient('test')
|
||||
|
||||
# Dataclass covert to json and send to server
|
||||
@dataclass
|
||||
class TestUser:
|
||||
name: str
|
||||
age: int
|
||||
|
||||
def send_data():
|
||||
i = TestUser("test", 123)
|
||||
with connector as conn:
|
||||
conn.send_data(i)
|
||||
data = conn.read_pipe()
|
||||
print(f"({type(data)}) {data=}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
send_data()
|
||||
27
examples/client_test_types.py
Normal file
27
examples/client_test_types.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import uuid
|
||||
|
||||
from winConnect import WinConnectClient
|
||||
|
||||
connector = WinConnectClient('test')
|
||||
|
||||
test_data = (
|
||||
[1, 2, 3, 4, 5], # List
|
||||
# {"test"}, # Set - Not supported
|
||||
{"test": "test"}, # Dict
|
||||
"test", # Str
|
||||
123, # Int
|
||||
123.456, # Float
|
||||
None, # None
|
||||
True, # Bool
|
||||
uuid.uuid4() # UUID; Transformed to str
|
||||
)
|
||||
|
||||
def send_data():
|
||||
with connector as conn:
|
||||
for i in test_data:
|
||||
conn.send_data(i)
|
||||
data = conn.read_pipe()
|
||||
print(f"({type(data)}) {data=}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
send_data()
|
||||
@@ -1,8 +0,0 @@
|
||||
from winConnect import WinConnectDaemon
|
||||
|
||||
connector = WinConnectDaemon('test')
|
||||
connector.set_header_settings(">L")
|
||||
|
||||
for data in connector.listen():
|
||||
print(data)
|
||||
connector.send_data(data)
|
||||
14
examples/echo_server.py
Normal file
14
examples/echo_server.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from winConnect import WinConnectDaemon
|
||||
|
||||
connector = WinConnectDaemon('test')
|
||||
# Set header settings
|
||||
# see: https://docs.python.org/3.13/library/struct.html#format-characters
|
||||
# Default: ">L"
|
||||
# >L - Big-endian long integer (header_size: 4 bytes, max_size: 4294967295)
|
||||
connector.set_header_settings(">L")
|
||||
|
||||
for data in connector.listen():
|
||||
print(f"({type(data)}) {data=}")
|
||||
if data is None and connector.closed:
|
||||
break
|
||||
connector.send_data(data)
|
||||
Reference in New Issue
Block a user