Name | super-easy-socket JSON |
Version |
0.0.2
JSON |
| download |
home_page | None |
Summary | A Python module designed to simplify the implementation of socket-based server-client communication |
upload_time | 2024-06-22 14:24:27 |
maintainer | None |
docs_url | None |
author | Theodor Billek |
requires_python | None |
license | MIT |
keywords |
super-easy-socket
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# super-easy-socket
`super-easy-socket` is a Python module designed to simplify the implementation of socket-based server-client communication. It provides an easy-to-use API for creating servers and clients that can send and receive messages, handle custom functions, and manage connections.
## Features
- Easy-to-use server and client classes.
- Support for custom functions associated with specific keywords.
- Automatic ping and pong for connection health monitoring.
- Threaded handling of client connections on the server side.
## Installation
You can install `super-easy-socket` using pip:
```bash
pip install super-easy-socket
```
## Usage
### Server Side
The server listens for incoming client connections and can handle custom functions based on keywords.
#### Example Server (server.py)
```python
from super_easy_socket import Server
# Define custom functions to handle specific keywords
def handle_message(client, payload):
print(f"Received from {client.ip}: {payload}")
if payload == 'hello':
client.send('response', 'Hello, client!')
elif payload == 'bye':
client.send('response', 'Goodbye, client!')
client.close_connection()
# Create a server object
my_server = Server(('127.0.0.1', 8080), 5)
# Associate functions with keywords
my_server.New_Function('message', handle_message)
# Start the server
my_server.start(ping=True)
```
### Client Side
The client connects to a server and can send messages or handle responses based on custom functions.
#### Example Client (client.py)
```python
from super_easy_socket import Client
# Define custom functions to handle specific keywords from the server
def handle_response(server, payload):
print(f"Received from server: {payload}")
if payload == 'Goodbye, client!':
client.close_connection()
# Define a function to run when connected to the server
def on_connect(client):
client.send('message', 'hello')
# Create a client object
my_client = Client(('127.0.0.1', 8080))
# Associate functions with keywords
my_client.New_Function('response', handle_response)
my_client.on_connect(on_connect)
# Connect to the server
my_client.connect(ping=True)
```
## How to Use
### Server Class
#### Creating a Server
```python
my_server = Server(('127.0.0.1', 8080), 5)
```
- `('127.0.0.1', 8080)`: Server IP address and port.
- `5`: Maximum number of clients.
#### Associating Functions with Keywords
```python
my_server.New_Function('message', handle_message)
```
- `'message'`: Keyword that triggers the function.
- `handle_message`: Function to be executed when the keyword is received.
#### Starting the Server
```python
my_server.start(ping=True)
```
- `ping=True`: Enable ping for connection health monitoring.
### Client Class
#### Creating a Client
```python
my_client = Client(('127.0.0.1', 8080))
```
- `('127.0.0.1', 8080)`: Server IP address and port.
#### Associating Functions with Keywords
```python
my_client.New_Function('response', handle_response)
```
- `'response'`: Keyword that triggers the function.
- `handle_response`: Function to be executed when the keyword is received.
#### Setting a Function to Run on Connect
```python
my_client.on_connect(on_connect)
```
- `on_connect`: Function to run when the client successfully connects to the server.
#### Connecting to the Server
```python
my_client.connect(ping=True)
```
- `ping=True`: Enable ping for connection health monitoring.
### Sending Messages
Messages are sent using the `send` method, which associates a keyword with a message payload. The receiving side will use the associated keyword to trigger the corresponding function.
#### Server Side Sending
To send a message from the server to the client:
```python
client.send('response', 'Hello, client!')
```
- `'response'`: The keyword associated with the message.
- `'Hello, client!'`: The message payload.
#### Client Side Sending
To send a message from the client to the server:
```python
my_client.send('message', 'hello')
```
- `'message'`: The keyword associated with the message.
- `'hello'`: The message payload.
## License
This module is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "super-easy-socket",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "super-easy-socket",
"author": "Theodor Billek",
"author_email": "HilbertLooked@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/46/c6/882a1a4c0b50b674b42b022b94363f66903aa510ad7c324f72da010c7d32/super-easy-socket-0.0.2.tar.gz",
"platform": null,
"description": "# super-easy-socket\r\n\r\n`super-easy-socket` is a Python module designed to simplify the implementation of socket-based server-client communication. It provides an easy-to-use API for creating servers and clients that can send and receive messages, handle custom functions, and manage connections.\r\n\r\n## Features\r\n- Easy-to-use server and client classes.\r\n- Support for custom functions associated with specific keywords.\r\n- Automatic ping and pong for connection health monitoring.\r\n- Threaded handling of client connections on the server side.\r\n\r\n## Installation\r\nYou can install `super-easy-socket` using pip:\r\n\r\n```bash\r\npip install super-easy-socket\r\n```\r\n\r\n## Usage\r\n\r\n### Server Side\r\nThe server listens for incoming client connections and can handle custom functions based on keywords.\r\n\r\n#### Example Server (server.py)\r\n```python\r\nfrom super_easy_socket import Server\r\n\r\n# Define custom functions to handle specific keywords\r\ndef handle_message(client, payload):\r\n print(f\"Received from {client.ip}: {payload}\")\r\n if payload == 'hello':\r\n client.send('response', 'Hello, client!')\r\n elif payload == 'bye':\r\n client.send('response', 'Goodbye, client!')\r\n client.close_connection()\r\n\r\n# Create a server object\r\nmy_server = Server(('127.0.0.1', 8080), 5)\r\n\r\n# Associate functions with keywords\r\nmy_server.New_Function('message', handle_message)\r\n\r\n# Start the server\r\nmy_server.start(ping=True)\r\n```\r\n\r\n### Client Side\r\nThe client connects to a server and can send messages or handle responses based on custom functions.\r\n\r\n#### Example Client (client.py)\r\n```python\r\nfrom super_easy_socket import Client\r\n\r\n# Define custom functions to handle specific keywords from the server\r\ndef handle_response(server, payload):\r\n print(f\"Received from server: {payload}\")\r\n if payload == 'Goodbye, client!':\r\n client.close_connection()\r\n\r\n# Define a function to run when connected to the server\r\ndef on_connect(client):\r\n client.send('message', 'hello')\r\n\r\n# Create a client object\r\nmy_client = Client(('127.0.0.1', 8080))\r\n\r\n# Associate functions with keywords\r\nmy_client.New_Function('response', handle_response)\r\nmy_client.on_connect(on_connect)\r\n\r\n# Connect to the server\r\nmy_client.connect(ping=True)\r\n```\r\n\r\n## How to Use\r\n\r\n### Server Class\r\n\r\n#### Creating a Server\r\n```python\r\nmy_server = Server(('127.0.0.1', 8080), 5)\r\n```\r\n- `('127.0.0.1', 8080)`: Server IP address and port.\r\n- `5`: Maximum number of clients.\r\n\r\n#### Associating Functions with Keywords\r\n```python\r\nmy_server.New_Function('message', handle_message)\r\n```\r\n- `'message'`: Keyword that triggers the function.\r\n- `handle_message`: Function to be executed when the keyword is received.\r\n\r\n#### Starting the Server\r\n```python\r\nmy_server.start(ping=True)\r\n```\r\n- `ping=True`: Enable ping for connection health monitoring.\r\n\r\n### Client Class\r\n\r\n#### Creating a Client\r\n```python\r\nmy_client = Client(('127.0.0.1', 8080))\r\n```\r\n- `('127.0.0.1', 8080)`: Server IP address and port.\r\n\r\n#### Associating Functions with Keywords\r\n```python\r\nmy_client.New_Function('response', handle_response)\r\n```\r\n- `'response'`: Keyword that triggers the function.\r\n- `handle_response`: Function to be executed when the keyword is received.\r\n\r\n#### Setting a Function to Run on Connect\r\n```python\r\nmy_client.on_connect(on_connect)\r\n```\r\n- `on_connect`: Function to run when the client successfully connects to the server.\r\n\r\n#### Connecting to the Server\r\n```python\r\nmy_client.connect(ping=True)\r\n```\r\n- `ping=True`: Enable ping for connection health monitoring.\r\n\r\n### Sending Messages\r\nMessages are sent using the `send` method, which associates a keyword with a message payload. The receiving side will use the associated keyword to trigger the corresponding function.\r\n\r\n#### Server Side Sending\r\nTo send a message from the server to the client:\r\n```python\r\nclient.send('response', 'Hello, client!')\r\n```\r\n- `'response'`: The keyword associated with the message.\r\n- `'Hello, client!'`: The message payload.\r\n\r\n#### Client Side Sending\r\nTo send a message from the client to the server:\r\n```python\r\nmy_client.send('message', 'hello')\r\n```\r\n- `'message'`: The keyword associated with the message.\r\n- `'hello'`: The message payload.\r\n\r\n## License\r\nThis module is licensed under the MIT License.\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python module designed to simplify the implementation of socket-based server-client communication",
"version": "0.0.2",
"project_urls": null,
"split_keywords": [
"super-easy-socket"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "46c6882a1a4c0b50b674b42b022b94363f66903aa510ad7c324f72da010c7d32",
"md5": "02f55426c4c76445e698087a0101924f",
"sha256": "bda70a420845942a3c5af520ba3aa02c81bbe4d940ef66c70d0a33ac5aa2d675"
},
"downloads": -1,
"filename": "super-easy-socket-0.0.2.tar.gz",
"has_sig": false,
"md5_digest": "02f55426c4c76445e698087a0101924f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 2160122,
"upload_time": "2024-06-22T14:24:27",
"upload_time_iso_8601": "2024-06-22T14:24:27.680236Z",
"url": "https://files.pythonhosted.org/packages/46/c6/882a1a4c0b50b674b42b022b94363f66903aa510ad7c324f72da010c7d32/super-easy-socket-0.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-22 14:24:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "super-easy-socket"
}