Python Forum
Question concerning function of a a socket
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question concerning function of a a socket
#1
My reverse engineering of torchat has led me to a question which I am unable to answer. When I look at the torchat source code, there is a file named tc_client.py, which contains the class “Listener“.

class Listener(threading.Thread):
    def __init__(self, buddy_list, socket=None):
        threading.Thread.__init__(self)
        self.buddy_list = buddy_list
        self.conns = []
        self.socket = socket
        self.start()
        self.startTimer()

    def run(self):
        self.running = True
        if not self.socket:
            interface = config.get("client", "listen_interface")
            port = config.getint("client", "listen_port")
            self.socket = tryBindPort(interface, port)
        self.socket.listen(5)
        while self.running:
            try:
                conn, address = self.socket.accept()
                self.conns.append(InConnection(conn, self.buddy_list))
                print "(2) new incoming connection"
                print "(2) have now %i incoming connections" % len(self.conns)
            except:
                print "socket listener error!"
                tb()
                self.running = False


    . . .
On line 19 of the code above, there is a socket on which the accept-method is called. As far as I know, the accept method can only be called on a server socket (I come from the JAVA world, where there exists a difference between a Socket and a ServerSocket object). Is the mentioned socket a server socket?
Reply


Messages In This Thread
Question concerning function of a a socket - by pkm - Jan-17-2019, 06:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  socket.connect question about parenthesis pace 1 2,403 Jan-30-2021, 08:17 AM
Last Post: Gribouillis
  Function that searches and shows all socket hosts shaanukstar123 1 2,192 Jan-30-2020, 05:52 PM
Last Post: Gribouillis
  UDP Socket Basic question zeeshannnetwork 2 3,155 Sep-10-2018, 02:25 AM
Last Post: zeeshannnetwork
  Raw socket sendto function errors IronReign 5 6,547 Jul-09-2017, 04:46 PM
Last Post: Blue Dog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020