Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import socket
- import sys
- # Tutaj podajemy adres IP własnej maszyny i port
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- # Connect the socket to the port where the server is listening
- server_address = ('localhost', 10000)
- print('connecting to {} port {}'.format(*server_address))
- sock.connect(server_address)
- while True:
- try:
- # Send data
- get_message = input()
- message = get_message.encode()
- print('Client: {!r}'.format(get_message))
- sock.sendall(message)
- # Look for the response
- amount_received = 0
- amount_expected = len(message)
- while amount_received < amount_expected:
- data = sock.recv(1024).decode()
- amount_received += len(data)
- print('Server: {!r}'.format(data))
- finally:
- True
- print('closing socket')
- sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement