Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. #! /usr/bin/python
  2. ## testing client
  3.  
  4. import socket, sys, threading, os
  5. from time import sleep
  6.  
  7. def send(msg): ## sends message to server
  8. clientConnection.send(msg)
  9.  
  10. def receiver():
  11. run = 1
  12. while run == 1:
  13. data = clientConnection.recv(4048)
  14. if data != "":
  15. print "\n" + data
  16. #print userID + " >> "
  17. if data == ".exit":
  18. print "attempting to exit"
  19. exit()
  20. sleep(2)
  21.  
  22. def main():
  23. global clientConnection
  24. clientConnection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  25. clientConnection.connect(("localhost", 901))
  26. th = threading.Thread(target=receiver)
  27. #th.setDaemon(1)
  28. print
  29. try:
  30. os.system("clear")
  31. except:
  32. os.system("cls")
  33. user = raw_input("username: ")
  34. passw = raw_input("password: ")
  35. info = user + " " + passw
  36. clientConnection.send(info)
  37. message = clientConnection.recv(16)
  38. if message == "AUTH_OK":
  39. print "auth ok"
  40. run = 1
  41. while run == 1:
  42. message = raw_input(">> ")
  43. if message == "/exit":
  44. print "received exit signal"
  45. th.join(2)
  46. run = 0
  47. send(message)
  48. try:
  49. th.start()
  50. except:
  51. pass
  52. exit()
  53. if message == "AUTH_FAIL_USER":
  54. print "auth failed"
  55. print "no user doesn't exist"
  56. sleep(3)
  57. clientConnection.close()
  58. main()
  59. if message == "AUTH_FAIL_PASS":
  60. print "auth failed"
  61. print "bad password"
  62. sleep(3)
  63. clientConnection.close()
  64. main()
  65. clientConnection.close()
  66.  
  67. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement