pj_crypto_v2/client_test_1.py
2019-11-06 14:23:34 +01:00

35 lines
875 B
Python

import socket
import sys
# Create a TCP/IP socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Connect the socket to the port where the server is listening
server_address = ('localhost', 15555)
print('connecting to {} port {}'.format(*server_address))
sock.connect(server_address)
try:
# Send data
message = b'This is the message. It will be repeated.'
print('sending {!r}'.format(message))
sock.sendall(message)
quit_msg_code = b'|<--eos-->|'
# Look for the response
amount_received = 0
amount_expected = len(message)
while amount_received < amount_expected:
#while 1:
data = sock.recv(16)
amount_received += len(data)
print('received {!r}'.format(data))
print('will send \'eos\' signal')
sock.sendall(quit_msg_code)
finally:
print('closing socket')
sock.close()