Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/python
- ## testing client
- import socket, sys, threading, os
- from time import sleep
- def send(msg): ## sends message to server
- clientConnection.send(msg)
- def receiver():
- run = 1
- while run == 1:
- data = clientConnection.recv(4048)
- if data != "":
- print "\n" + data
- #print userID + " >> "
- if data == ".exit":
- print "attempting to exit"
- exit()
- sleep(2)
- def main():
- global clientConnection
- clientConnection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- clientConnection.connect(("localhost", 901))
- th = threading.Thread(target=receiver)
- #th.setDaemon(1)
- print
- try:
- os.system("clear")
- except:
- os.system("cls")
- user = raw_input("username: ")
- passw = raw_input("password: ")
- info = user + " " + passw
- clientConnection.send(info)
- message = clientConnection.recv(16)
- if message == "AUTH_OK":
- print "auth ok"
- run = 1
- while run == 1:
- message = raw_input(">> ")
- if message == "/exit":
- print "received exit signal"
- th.join(2)
- run = 0
- send(message)
- try:
- th.start()
- except:
- pass
- exit()
- if message == "AUTH_FAIL_USER":
- print "auth failed"
- print "no user doesn't exist"
- sleep(3)
- clientConnection.close()
- main()
- if message == "AUTH_FAIL_PASS":
- print "auth failed"
- print "bad password"
- sleep(3)
- clientConnection.close()
- main()
- clientConnection.close()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement