38 lines
963 B
Python
Executable File
38 lines
963 B
Python
Executable File
import socket
|
|
import sys
|
|
from utils.send_receive import *
|
|
|
|
# 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))
|
|
send_msg(sock, message)
|
|
#sock.sendall(message)
|
|
quit_msg_code = b'|<--eos-->|'
|
|
|
|
# Look for the response
|
|
#amount_received = 0
|
|
#amount_expected = len(message)
|
|
|
|
while data != quit_msg_code:
|
|
#while 1:
|
|
#data = sock.recv(16)
|
|
#amount_received += len(data)
|
|
#print('received {!r}'.format(data))
|
|
data = recv_msg(sock)
|
|
print('will send \'eos\' signal')
|
|
sock.sendall(quit_msg_code)
|
|
|
|
finally:
|
|
print('closing socket')
|
|
sock.close()
|