#!/usr/bin/python import socket my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #the first parameter indicates that #the socket is an internet socket #and the second parameter indicates #that it uses TCP HOST = "127.0.0.1" # Loopback interface PORT = 1060 # Sufficiently obscure port # method written by Brandon Rhodes/John Goerzen in Foundations of Python Network Programming def recv_all(sock, length): data = '' while len(data) < length: more = sock.recv(length - len(data)) if not more: raise EOFError('socket closed') data += more return data my_socket.connect((HOST, PORT)) msg = raw_input("Please type your message: ") length = "000" + str(len(msg)) length = length[-3:] print length lengthint = int(length) msg = msg[:lengthint] my_socket.sendall(length) print len(msg) my_socket.sendall(msg) recv_all(my_socket, 3) my_socket.close()