Created
May 23, 2020 13:19
-
-
Save gabihodoroaga/358af2df0d68d9c555182b688f9563f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', 5555) | |
print >>sys.stderr, 'connecting to %s port %s' % server_address | |
sock.connect(server_address) | |
try: | |
# Send data | |
message = 'This is the message. It will be repeated.' | |
print >>sys.stderr, 'sending "%s"' % message | |
sock.sendall(message) | |
# Look for the response | |
amount_received = 0 | |
amount_expected = len(message) | |
while amount_received < amount_expected: | |
data = sock.recv(16) | |
amount_received += len(data) | |
print >>sys.stderr, 'received "%s"' % data | |
finally: | |
print >>sys.stderr, 'closing socket' | |
sock.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment