Skip to content

Instantly share code, notes, and snippets.

@icarocamelo
Last active September 9, 2015 19:14
Show Gist options
  • Save icarocamelo/b3b083e8852d2cb8d231 to your computer and use it in GitHub Desktop.
Save icarocamelo/b3b083e8852d2cb8d231 to your computer and use it in GitHub Desktop.
simple socket client
#client example
import socket
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Connecting...'
client_socket.connect(('127.0.0.1', 8887))
print 'Connected'
while 1:
data = client_socket.recv(512)
if ( data == 'q' or data == 'Q'):
client_socket.close()
break;
else:
print "RECEIVED:" , data
data = raw_input ( "SEND( TYPE q or Q to Quit):" )
if (data <> 'Q' and data <> 'q'):
client_socket.send(data)
else:
client_socket.send(data)
client_socket.close()
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment