Added a try except

I added a try: except that reconnects if network breaks
This commit is contained in:
Yanis Boucherk 2021-03-17 22:07:05 +01:00 committed by GitHub
parent 74559a15a8
commit 6027b4a6b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 22 deletions

View File

@ -1,7 +1,7 @@
import socket, hashlib import socket, hashlib
# Global variables # Global variables
soc = socket.socket() soc = socket.socket()
username = "user" # Edit this to your username, mind the quotes username = "Yanis" # Edit this to your username, mind the quotes
pool_address = "51.15.127.80" pool_address = "51.15.127.80"
pool_port = 2811 pool_port = 2811
@ -13,6 +13,7 @@ while True:
print("Server is on version", server_version) print("Server is on version", server_version)
# Mining section # Mining section
while True: while True:
try:
soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request
# Don't mind the "ESP32" for now since it is in an early state # Don't mind the "ESP32" for now since it is in an early state
@ -32,4 +33,7 @@ while True:
) # Send result of hashing algorithm to pool ) # Send result of hashing algorithm to pool
feedback = soc.recv(1024).decode() # Get feedback about the result feedback = soc.recv(1024).decode() # Get feedback about the result
print(feedback) print(feedback)
except:
soc.close()
soc = socket.socket()
soc.connect((str(pool_address), int(pool_port))) # Connect to the server