def start(self): HOST = '127.0.0.1' # Symbolic name meaning the local host PORT = 56666 # Arbitrary non-privileged port self.s = getSocket(HOST, PORT, "server") if self.s is None: sys.stderr.write('Could not open socket') # No way sys.exit(1) while 1: try: conn, addr = self.s.accept() data = conn.recv(1024) conn.close() # If the quitting flag has been set, or we've been asked to close if self.utility.abcquitting or data == "Close Connection": self.s.close() break # elif data == "KEEPALIVE": # # just making sure the connection doesn't timeout... # pass elif data == "Raise Window": self.utility.frame.onTaskBarActivate() else: self.utility.queue.addtorrents.AddTorrentFromFile(data) except wx.PyDeadObjectError: toosoontext = "\nTried to start ABC again too soon after exiting!\n" + \ "(Wait for ABC to finish shutting down, then try again)\n" sys.stderr.write(toosoontext) break
def startThread(self): self.s = getSocket(self.ip, self.port, "server") if self.s is None: #Display Dialog Can't open scoket dlg = wx.MessageDialog(None, self.utility.lang.get('cantopensocket') , self.utility.lang.get('socketerror'), wx.OK|wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() self.active = False self.updateLabels() return WebServiceCmd(self).go()
def sendmesg(self, mesg): HOST = self.ip # The remote host PORT = self.port # The same port as used by the server s = getSocket(HOST, PORT) if s is None: return "Can't connect ABC web service" # if request is not close connection request # so it's torrent request copy .torrent # in backup torrent folder ############################################## s.send(mesg) retmesg = s.recv(5000) s.close() return retmesg
def ClientPassParam(params, ignoreError=False): HOST = '127.0.0.1' # The remote host PORT = 56666 # The same port as used by the server # Keep on trying... # (at least moreso than before) s = getSocket(HOST, PORT, 15) if s is None: if ignoreError: return print 'could not open socket' # sys.stderr.write("Could not open socket\n") # sys.stderr.write("--Trying to send params: (" + params + ")\n") sys.exit(1) # if request is not close connection request # so it's torrent request copy .torrent # in backup torrent folder ############################################## if not params: s.send("Raise Window") else: s.send(params) s.close()
def ClientPassParam(params, ignoreError = False): HOST = '127.0.0.1' # The remote host PORT = 56666 # The same port as used by the server # Keep on trying... # (at least moreso than before) s = getSocket(HOST, PORT, 15) if s is None: if ignoreError: return print 'could not open socket' # sys.stderr.write("Could not open socket\n") # sys.stderr.write("--Trying to send params: (" + params + ")\n") sys.exit(1) # if request is not close connection request # so it's torrent request copy .torrent # in backup torrent folder ############################################## if not params: s.send("Raise Window") else: s.send(params) s.close()
def sendCmd(self, command): # Web service isn't even active -- don't bother sending a message if not self.webserver.active: return False HOST = self.webserver.ip # The remote host PORT = self.webserver.port # The same port as used by the server s = getSocket(HOST, PORT) if s is None: dlg = wx.MessageDialog(None, self.utility.lang.get('cantconnectabcwebinterface') , self.utility.lang.get('socketerror'), wx.OK|wx.ICON_ERROR) dlg.ShowModal() dlg.Destroy() return False # if request is not close connection request # so it's torrent request copy .torrent # in backup torrent folder ############################################## mesg = "ID|" + self.utility.webconfig.Read('webID') + "\n" + command s.send(mesg) s.close() return True