-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UPD: add TCPClient, move old version to examples
- Loading branch information
Showing
37 changed files
with
389 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.6.1" | ||
__version__ = "0.7.0" |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
1 change: 1 addition & 0 deletions
1
QtPyNetwork2/balancers/__init__.py → QtPyNetwork/balancer/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .AbstractBalancer import AbstractBalancer | ||
from .NoBalancer import NoBalancer | ||
from .ThreadBalancer import ThreadBalancer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from qtpy.QtCore import Slot, Signal, QObject | ||
|
||
from abc import abstractmethod | ||
|
||
|
||
class AbstractClient(QObject): | ||
|
||
connected = Signal(str, int) | ||
disconnected = Signal() | ||
message = Signal(bytes) | ||
error = Signal(Exception) | ||
closed = Signal() | ||
failed_to_connect = Signal() | ||
|
||
def __init__(self, timeout: int = 5): | ||
super(AbstractClient, self).__init__() | ||
self._socket = None | ||
self._timeout = timeout | ||
|
||
@abstractmethod | ||
@Slot(str, int) | ||
def start(self, ip: str, port: int): | ||
"""Start client thread and connect to server.""" | ||
pass | ||
|
||
@abstractmethod | ||
@Slot(bytes) | ||
def write(self, data: bytes): | ||
"""Write data to server. | ||
Args: | ||
data (bytes): Data to write. | ||
""" | ||
pass | ||
|
||
@Slot(str, int) | ||
def on_connected(self, ip, port): | ||
"""Called when client connects to server. | ||
Emits connected signal. | ||
Args: | ||
ip (str): Client ip address. | ||
port (int): Client port. | ||
""" | ||
self.connected.emit(ip, port) | ||
|
||
def on_message(self, message: bytes): | ||
"""Called when client receives message from server. | ||
Emits message signal. | ||
Args: | ||
message (bytes): Message. | ||
""" | ||
self.message.emit(message) | ||
|
||
@Slot() | ||
def on_disconnected(self): | ||
"""Called when device disconnects from server. | ||
Emits disconnected signal.""" | ||
self.disconnected.emit() | ||
|
||
@Slot(str) | ||
def on_error(self, error: str): | ||
"""Called when a socket error occurs. | ||
Emits error signal. | ||
Args: | ||
error (str): Error string. | ||
""" | ||
self.error.emit(Exception, error) | ||
|
||
@Slot() | ||
def on_failed_to_connect(self): | ||
"""Called when client fails to connect to server. | ||
Emits failed_to_connect signal. | ||
""" | ||
self.failed_to_connect.emit() | ||
|
||
@Slot() | ||
def on_closed(self): | ||
"""Called when the socket is closed. | ||
Emits closed signal.""" | ||
self.closed.emit() | ||
|
||
@Slot() | ||
def close(self): | ||
"""Disconnect from server and close socket.""" | ||
if self._socket: | ||
self._socket.close() | ||
self._socket = None | ||
self.closed.emit() | ||
|
||
@Slot() | ||
def is_running(self): | ||
"""Check if client is running.""" | ||
return self._socket is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.