try sock socket socket socket AF_INET socket SOCK_STREAM try sock conn

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((host, port))
length = len(message)
lengthOfLength = len(str(length))
sock.send(chr(lengthOfLength) + str(length) + message)
return someReturningValue
except SocketError, err:
print "Error: %s\n" % str(err)
finally:
sock.close()