
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
A simple Python module for creating a TCP chat connection between two computers to send commands or information.
TcpChat is a simple Python module for creating a TCP chat connection between two computers to send commands or information. GitHub, PyPi
Use the package manager pip to install TcpChat.
pip install ct-tcpchat
from ct_tcpchat import TcpChat
import logging
def callback_function(message):
print(f"Received message: {message}")
connect_to_ip = "192.168.1.50" # Enter the IP Address from the other computer
on_port = 44785 # Choose a port for the connection. (Optional. Default = 44785)
connection = TcpChat(connect_to_ip, callback_function, on_port, log_level=logging.INFO)
connection.start()
# Example of sending a message from the main thread
connection.send_message("Hello from server")
This library provides two classes for TCP communication: TcpChat
and TcpChatBlocking
. Each class serves different purposes based on the need for non-blocking or blocking operations.
The TcpChat
class is designed for non-blocking TCP communication by leveraging Python's threading capabilities. This class allows for concurrent handling of server and client connections, ensuring that the main application remains responsive and can handle other tasks simultaneously.
Key Features:
Usage Example:
from ct_tcpchat import TcpChat
import logging
import time
def callback_function(message):
print(f"Received message: {message}")
connect_to_ip = "192.168.1.50"
port = 44785
log_level = logging.DEBUG
connection = TcpChat(connect_to_ip=connect_to_ip, callback=callback_function, port=port, log_level=log_level)
connection.retry_connection_interval = 2
if __name__ == "__main__":
try:
connection.start()
while not connection.connected_event.is_set():
time.sleep(1)
while connection.connected_event.is_set():
message = input("Message: ")
if message:
connection.send_message(message)
except KeyboardInterrupt:
print("\nExiting program...")
connection.close_connections()
The TcpChatBlocking
class is designed for blocking TCP communication without using threading. This class is suitable for applications where the user wants to control the main loop and manage threading themselves or where the simplicity of blocking operations is desired.
Key Features:
Usage Example:
from ct_tcpchat import TcpChatBlocking
import logging
import time
def callback_function(message):
print(f"Received message: {message}")
connect_to_ip = "192.168.1.50"
port = 44785
log_level = logging.DEBUG
connection = TcpChatBlocking(connect_to_ip=connect_to_ip, callback=callback_function, port=port, log_level=log_level)
connection.retry_connection_interval = 2
if __name__ == "__main__":
try:
connection.start()
while True:
message = input("Message: ")
if message:
connection.send_message(message)
connection.process_events()
except KeyboardInterrupt:
print("\nExiting program...")
connection.close_connections()
Threading:
TcpChat
uses threading, making it non-blocking and suitable for applications requiring concurrency.TcpChatBlocking
does not use threading, making it blocking and simpler but requiring the user to manage the main loop.Main Loop Management:
TcpChat
automatically manages its own threads for server and client operations.TcpChatBlocking
provides methods to be called in the user's main loop, giving the user more control over the execution flow.Use Case Suitability:
TcpChat
is ideal for applications needing responsiveness and concurrency, such as GUIs or real-time systems.TcpChatBlocking
is ideal for simpler applications or where the user prefers to manage threading themselves, such as in command-line tools or basic scripts.TcpChat.get_local_ip() # Returns own IP Address
TcpChat.close_connections() # Closes all the connections
TcpChat.retry_connection_interval = 2 # Set the retry interval (Default = 5 seconds)
MIT
FAQs
A simple Python module for creating a TCP chat connection between two computers to send commands or information.
We found that ct-tcpchat demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.