Skip to content

A generic python socket wrapper using sockect and queue

Notifications You must be signed in to change notification settings

600lyy/python_socket_wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

python_socket_wrapper

A generic python socket wrapper using sockect and queue

use like so:

from python_socket_wapper import SocketThread
class ClientA(SocketThread):

    def __init__(self):
        self.send_queue = Queue.Queue()
        self.receive_queue = Queue.Queue()
        self.socket_thread = SocketThread(
                                address=(ip, port),
                                send_queue=self.send_queue,
                                receive_queue=self.receive_queue,
                            )
        self.socket_thread.start()
        self.socket_thread.join()

    def send(self, msg):
        self.send_queue.put(msg)

    def receive(self, timeout):
        self.receive_queue.get(timeout=timeout)

    def disconnect(self):
        self.socket_thread.stop()

SocketThread includes a blocking socket with a timer of 0.2 second. Therefore the SocketThread will be suspended by OS for at least 0.2 seoncd if there is no data to read from the socket receive buffer

A socket object can be in one of three modes: blocking, non-blocking, or timeout. Sockets are by default always created in blocking mode, but this can be changed by calling setdefaulttimeout().

About

A generic python socket wrapper using sockect and queue

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published