Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sqlite3
- import thread
- ip = "192.168.2.106"
- #ip = "10.2.2.179"
- port = 8888
- LOG_IN = "101"
- LOG_IN_RES = "102"
- ECHO = "103"
- def main():
- servSoc = socket.socket()
- servSoc.bind((ip, port))
- i = 0
- while True:
- i+=1
- servSoc.listen(1)
- client_soc, client_addr = servSoc.accept()
- thread.start_new_thread(serve, (client_soc,))
- print i
- def serve(soc):
- protocol = {LOG_IN : log_in}
- while True:
- try:
- msg = soc.recv(1024)
- if msg[0:3] == LOG_IN:
- protocol[LOG_IN](soc, msg[3:])
- else:
- send(soc, LOG_IN_RES, "-1")
- except:
- return None
- def log_in(soc, data):
- db = sqlite3.connect("myDB.db")
- curr = db.cursor()
- name = data[2 : int(data[0:2]) + 2]
- password = data[int(data[0:2]) + 4 : ]
- curr.execute("SELECT * FROM Users WHERE Username = \'" + name + "\'AND Password = \'" + password + "\'")
- rows = curr.fetchall()
- curr.close()
- if len(rows) is not 0:
- res = "1"
- else:
- res = "0"
- send(soc, LOG_IN_RES, res)
- def send(soc, msg_type, msg):
- soc.send(msg_type + msg)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement