📄 interconn.py
字号:
# Echo server program
from wxPython.wx import *
from wxPython import *
import socket
#import sys
from os import path, getcwd
from shutil import copyfile
###################################################################################################
# ServerListener Class:
# Single Instance opens local port for taking parameter from other instances
###################################################################################################
class ServerListener:
def __init__(self):
self.s = None
def start(self, parent):
HOST = '127.0.0.1' # Symbolic name meaning the local host
PORT = 56666 # Arbitrary non-privileged port
self.parent = parent
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
af, socktype, proto, canonname, sa = res
try:
self.s = socket.socket(af, socktype, proto)
except socket.error, msg:
self.s = None
continue
try:
self.s.bind(sa)
self.s.listen(1)
except socket.error, msg:
self.s.close()
self.s = None
continue
break
if self.s is None:
print 'could not open socket' #Change to display dialogbox port already use
# Please change local port!
sys.exit(1)
while 1:
conn, addr = self.s.accept()
data = conn.recv(1024)
conn.close()
if data == "Please raise abc windows":
self.parent.parent.PopFrameUp()
elif data == "Please close connection!!":
self.s.close()
break
else:
src, dest = data.split("|")
try:
#duplicate file
f = open(dest, "r")
f.close()
dlg = wxMessageDialog(self.parent, "This torrent is duplicate!\nAre you sure to replace it?" , "Duplicate Torrent!", wxYES_NO|wxICON_EXCLAMATION)
if(dlg.ShowModal() == wxID_NO):
dlg.Destroy()
continue
except: #new torrent file
pass
copyfile(src, dest)
parent.queue.addNewProc(dest, False)
###################################################################################################
# ClientPassParam:
# Other instances except server pass parameter to a Single Instance process
# and close inmediately
###################################################################################################
def ClientPassParam(params, abcpath):
HOST = '127.0.0.1' # The remote host
PORT = 56666 # The same port as used by the server
s = None
for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM):
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error, msg:
s = None
continue
try:
s.connect(sa)
except socket.error, msg:
s.close()
s = None
continue
break
if s is None:
print 'could not open socket'
sys.exit(1)
# if request is not close connection request
# so it's torrent request copy .torrent
# in backup torrent folder
##############################################
if params == "":
s.send("Please raise abc windows")
else:
if params != "Please close connection!!":
location = path.join(abcpath, 'torrent', path.split(params)[1])
s.send(params+'|'+location)
else:
s.send(params)
s.close()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -