from socket import * # get socket constructor and constants myHost = '' # server machine, '' means local host myPort = 8888 # listen on a non-reserved port number if len(myHost) > 0: print "Server gestartet auf ", myHost,', Port: ',str(myPort) else: # print "Server gestartet auf localhost, Port: ",str(myPort) sock = socket(AF_INET, SOCK_STREAM) # make a TCP socket object sock.bind((myHost, myPort)) # bind it to server port number sock.listen(5) # allow upto 5 pending connects try: while 1: connection, address = sock.accept() print 'Server verbunden mit', address, ip_nr = address[0] # Client-IP data = connection.recv(1024) if data: ## print str(data), 'from', address connection.sendall('Password: ') data = connection.recv(1024) if data: ## pd = str(data) if pd == "tunix": print "Hallo, " + str(ip_nr) connection.sendall('Hallo, ' + str(ip_nr) ) while 1: data = connection.recv(1024) if data: ## print '<' + str(data) + '> from', address connection.sendall('Echo <' + str(data) + '> von ' + str(ip_nr) ) # connection.sendall(data) else: print "Verbindung beendet!" break else: connection.sendall('Sorry, wrong place, wrong time, . . .' ) print "Verbindung beendet!" finally: sock.close()