Example #1
0
    def __init__(self, host, port):
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            self.sock.connect((host, port))
            handshake(self.sock)

        except BrokenPipeError:
            print("\nパイプが切断されました。")
        except ConnectionRefusedError:
            print("\n接続できませんでした。HOST:{} PORT:{}".format(host, port))
        except KeyboardInterrupt:
            close(self.sock)
            receive(self.sock)
            print("\n切断しました。")
        except:
            raise
Example #2
0
def handle (client, addr):
	#handle websocket connection
	handshake.handshake(client)
	lock = threading.Lock()
	while 1:
		data = messaging.recv_data(client, 4096)
		if not data: break
		data = cgi.escape(data)
		file_name = file_handler.check_for_file(data)
		if file_name:
			data = file_handler.load_file(file_name)
		lock.acquire()
		[messaging.send_data(c, data) for c in clients]
		lock.release()
	print 'Client closed:', addr
	lock.acquire()
	clients.remove(client)
	lock.release()
	client.close()
Example #3
0
def handle(client, addr):
    #handle websocket connection
    handshake.handshake(client)
    lock = threading.Lock()
    while 1:
        data = messaging.recv_data(client, 4096)
        if not data: break
        data = cgi.escape(data)
        file_name = file_handler.check_for_file(data)
        if file_name:
            data = file_handler.load_file(file_name)
        lock.acquire()
        [messaging.send_data(c, data) for c in clients]
        lock.release()
    print 'Client closed:', addr
    lock.acquire()
    clients.remove(client)
    lock.release()
    client.close()
Example #4
0
 def test_composition4(self):
     inp = ['wink', 'double blink', 'jump']
     self.assertEqual(inp, handshake(code(inp)))
Example #5
0
 def test_composition3(self):
     self.assertEqual('111', code(handshake('111')))
Example #6
0
 def test_composition2(self):
     self.assertEqual('1', code(handshake(1)))
Example #7
0
 def test_composition1(self):
     self.assertEqual('11011', code(handshake(27)))
Example #8
0
 def test_shake_bin_invalid(self):
     self.assertEqual([], handshake('121'))
Example #9
0
 def test_shake_negative_int(self):
     self.assertEqual([], handshake(-9))
 def test_shake_bin_invalid(self):
     self.assertEqual([], handshake('121'))
 def test_shake_bin1(self):
     self.assertEqual(['close your eyes', 'double blink'], handshake('10110'))
 def test_composition4(self):
     inp = ['wink', 'double blink', 'jump']
     self.assertEqual(inp, handshake(code(inp)))
 def test_shake_int(self):
     self.assertEqual(['wink', 'jump'], handshake(9))
 def test_composition3(self):
     self.assertEqual('111', code(handshake('111')))
 def test_composition2(self):
     self.assertEqual('1', code(handshake(1)))
 def test_composition1(self):
     self.assertEqual('11011', code(handshake(27)))
Example #17
0
 def test_shake_int(self):
     self.assertEqual(['wink', 'jump'], handshake(9))
 def test_shake_bin2(self):
     self.assertEqual(['wink', 'close your eyes'], handshake('101'))
Example #19
0
 def test_shake_bin1(self):
     self.assertEqual(['close your eyes', 'double blink'],
                      handshake('10110'))
 def test_shake_negative_int(self):
     self.assertEqual([], handshake(-9))
Example #21
0
IP_addr = str(sys.argv[1])
Port = int(sys.argv[2])
Name = str(sys.argv[3])
password = str(sys.argv[4])

# create a directory where to store keys and received messages !!
CLIENT_DIR = f".keys_{Name}"
if not os.path.exists(CLIENT_DIR):
    os.makedirs(CLIENT_DIR)
os.chdir(CLIENT_DIR)

#bind the sever to the given ip and port
server.connect((IP_addr, Port))

## TODO  call handshake function
handshake(server, True, password)

#while True:
#
#    # maintains a list of possible input streams
#    sockets_list = [sys.stdin, server]
#
#    """ There are two possible input situations. Either the
#    user wants to give manual input to send to other people,
#    or the server is sending a message to be printed on the
#    screen. Select returns from sockets_list, the stream that
#    is reader for input. So for example, if the server wants
#    to send a message, then the if condition will hold true
#    below.If the user wants to send a message, the else
#    condition will evaluate as true"""
#    read_sockets,write_socket, error_socket = select.select(sockets_list,[],[])
Example #22
0
 def test_shake_bin2(self):
     self.assertEqual(['wink', 'close your eyes'], handshake('101'))