Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import socket
  2. import sys
  3. # Tutaj podajemy adres IP własnej maszyny i port
  4. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  5. # Connect the socket to the port where the server is listening
  6. server_address = ('localhost', 10000)
  7. print('connecting to {} port {}'.format(*server_address))
  8. sock.connect(server_address)
  9. while True:
  10. try:
  11. # Send data
  12. get_message = input()
  13. message = get_message.encode()
  14. print('Client: {!r}'.format(get_message))
  15. sock.sendall(message)
  16. # Look for the response
  17. amount_received = 0
  18. amount_expected = len(message)
  19. while amount_received < amount_expected:
  20. data = sock.recv(1024).decode()
  21. amount_received += len(data)
  22. print('Server: {!r}'.format(data))
  23. finally:
  24. True
  25. print('closing socket')
  26. sock.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement