Welcome to EasySocket, your go-to solution for building a Python socket server with ease. This lightweight framework allows you to integrate socket functionality quickly, making network programming straightforward and accessible.
- Effortless Integration: Quickly set up a socket server with minimal configuration.
- Lightweight: The framework is designed to be fast and efficient, without unnecessary overhead.
- Callback Support: Easily manage events and responses using callback functions.
- Minimal Setup: Get started with just a few lines of code.
- Python 3 Compatibility: Fully compatible with Python 3, ensuring modern programming practices.
To install EasySocket, simply clone the repository and install the required packages. Use the following commands:
git clone https://github.com/dionkaps7/EasySocket.git
cd EasySocket
pip install -r requirements.txtFor the latest releases, visit the Releases section. Download the latest version and execute the setup.
To get started with EasySocket, follow these simple steps:
- Import the EasySocket module in your Python script.
- Create an instance of the socket server.
- Define your callback functions to handle incoming connections and messages.
- Start the server.
Here’s a simple example to illustrate the process.
from easysocket import EasySocket
def on_connect(client_socket):
print("Client connected:", client_socket)
def on_message(client_socket, message):
print("Message received:", message)
client_socket.send("Message received".encode())
server = EasySocket(port=12345)
server.on_connect = on_connect
server.on_message = on_message
server.start()In this example, we define two callback functions: on_connect to handle new client connections and on_message to process incoming messages.
EasySocket supports various advanced features, including:
- Multi-threading: Handle multiple clients simultaneously.
- Custom Protocols: Easily define your own message formats.
- Error Handling: Robust error management to keep your server running smoothly.
Here’s a simple echo server example:
from easysocket import EasySocket
def on_message(client_socket, message):
client_socket.send(message)
server = EasySocket(port=12345)
server.on_message = on_message
server.start()This server will echo back any message it receives.
For a more complex application, consider a chat server that broadcasts messages to all connected clients:
from easysocket import EasySocket
clients = []
def on_connect(client_socket):
clients.append(client_socket)
def on_message(client_socket, message):
for client in clients:
if client != client_socket:
client.send(message)
server = EasySocket(port=12345)
server.on_connect = on_connect
server.on_message = on_message
server.start()This chat server keeps track of all connected clients and broadcasts messages to everyone except the sender.
Initializes the EasySocket server on the specified port.
Callback function that is called when a new client connects.
Callback function that is called when a message is received from a client.
Starts the socket server.
We welcome contributions to EasySocket! If you have suggestions or improvements, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes and commit them.
- Push your branch and create a pull request.
Please ensure your code follows our coding standards and includes tests where applicable.
EasySocket is licensed under the MIT License. See the LICENSE file for more details.
For any questions or issues, please check the Releases section. If you encounter problems, feel free to open an issue on GitHub.
Thank you for using EasySocket! We hope it simplifies your socket programming experience.