'Are Python 3 and sqlite3 enough for a socket login and how much do I expect to handle before it falls down?
I have a saved_auth table within an auth.db sqlite3 database on the user's side (inside an android.apk) and a thread that runs func_auth_socket().
Here is a part of the thread:
def func_auth_socket():
global auth_packet, auth_packet_answer, username, conto_auth_socket, decoded_auth_packet_answer, holdermsg
while conto_auth_socket == False:
try:
auth_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
auth_socket.connect(('192.168.1.138', 3367))
print('connected')
print('after conn '+ auth_packet)
while True:
if auth_packet != '':
print('sending auth packet: ' + auth_packet)
auth_socket.send(bytes(auth_packet, 'utf-8'))
auth_packet_answer = auth_socket.recv(100)
decoded_auth_packet_answer = auth_packet_answer.decode("utf-8")
print(decoded_auth_packet_answer)
conto_auth_socket = True
print(conto_auth_socket)
auth_socket.shutdown(socket.SHUT_RDWR)
auth_socket.close()
break
if decoded_auth_packet_answer == 'match':
username = auth_packet.split('|')[0]
print('recieved username: ' + username )
auth_socket.shutdown(socket.SHUT_RDWR)
auth_socket.close()
elif decoded_auth_packet_answer == 'unmatch':
auth_socket.shutdown(socket.SHUT_RDWR)
auth_socket.close()
else:
pass
except:
holdermsg = 'Initializing'
time.sleep(0.5)
holdermsg = 'Initializing .'
time.sleep(0.5)
holdermsg = 'Initializing ..'
time.sleep(0.5)
holdermsg = 'Intializing ...'
and inside the gui loop (threading kivy mainapp) I have this with some update functions:
def fun_socket_auth():
global auth_response2, auth_response1
socket_auth = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket_auth.bind(('192.168.1.138', 3416))
socket_auth.listen(10)
while True:
linktoauth = sqlite3.connect('USERS.db')
curs = linktoauth.cursor()
clientsocket, address = socket_auth.accept()
print(address[0])
while True:
auth_request = clientsocket.recv(100)
string_auth = auth_request.decode("utf-8")
user = string_auth.split('|')[0]
print(string_auth)
curs.execute("SELECT * FROM users WHERE username = ?", (user,))
select = curs.fetchone()
if select == None:
clientsocket.send(bytes('unmatch', "utf-8"))
auth_request= ''
string_auth = ''
user = ''
break
elif select[0]+'|'+ select[1] == user+'|'+ string_auth.split('|')[1]:
#if auth_request.decode("utf-8") == 'user|password':
clientsocket.send(bytes('match', "utf-8"))
auth_request = ''
string_auth = ''
user = ''
break
else:
clientsocket.send(bytes('unmatch', "utf-8"))
auth_request = ''
string_auth = ''
user = ''
break
# pass
fun_socket_auth()
This base model is working fine for a couple of virtual machines and I also can edit the server side to store every clientsocket in a list then answer to it, but the question is how do I know if I am overloaded with requests to what should I compare it? Is sqlite3 fast enough? Should I split the requests into two different servers, or different threads?.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
