Reputation: 127
i am trying to make a server-client md5 decription the server sends how many cores he have(cpu) and the client slices him th range for multiproccesing (brute force) but the server throws me the "socket.error: [Errno 10048] Only one usage of each socket address (protocol/network address/port) is normally permitted" error any suggestion?
client:
import socket
RANGE=10000
d="7a2b33c672ce223b2aa5789171ddde2f"
d=d.lower()
HOMEADDRES='127.0.0.1'
PORT=2345
ADDRESS=(HOMEADDRES,PORT)
my_socket=socket.socket(socket.AF_INET ,socket.SOCK_STREAM)
my_socket.connect((HOMEADDRES,PORT))
def main():
ranges=""
my_socket.send(d)
cores=int(my_socket.recv(1024))
borders=[0]
for i in range(1,cores+1):
borders.append(RANGE*i/cores)
for i in range(len(borders)):
ranges+=str(borders[i])+"#"
ranges=ranges[:-1]
print ranges
my_socket.send(ranges)
print my_socket.recv(1024)
my_socket.close()
if __name__ == '__main__':
main()
server:
import socket
import multiprocessing
import hashlib
IP_ADD='0.0.0.0'
PORT=2345
ADDRESS = (IP_ADD,PORT)
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind(ADDRESS)
server_socket.listen(1)
client_socket, address = server_socket.accept()
print "connected"
def decrypt(low,high,d):
print "1"
i=low
while i<high:
m=hashlib.md5()
m.update(str((i)))
if m.hexdigest()==d:
client_socket.send(i)
client_socket.close()
server_socket.close()
i+=1
def main():
d=client_socket.recv(1024)
client_socket.send(str(multiprocessing.cpu_count()))
borders=client_socket.recv(1024)
borders=borders.split("#")
for i in range(len(borders)-1):
p=multiprocessing.Process(target=decrypt, args=(borders[i],borders[i+1],d))
p.start()
if __name__ == '__main__':
main()
Upvotes: 0
Views: 6726
Reputation: 1
The below python idiom solved this for me
if __name__ == "__main__":
app = web.Application()
web.run_app(app)
Upvotes: 0
Reputation: 2847
You're creating your server socket in the module scope so as soon as the module is imported, it is created and bound to (0.0.0.0, 2345).
Multiprocessing will cause the module to be (re)imported in the new process it creates, so that process will immediately try to create the same server socket on port 2345 and that is impossible.
My suggestion is either don't create your server socket in the module scope but do it in main() or move the multiprocessing stuff into its own module.
Upvotes: 0