LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   indentation error in python simple socket program (https://www.linuxquestions.org/questions/programming-9/indentation-error-in-python-simple-socket-program-786460/)

xskycamefalling 02-02-2010 10:26 AM

indentation error in python simple socket program
 
hi all i was recently building on a simple socket program i had written in python basically like a little chat client but i added a server_socket.close command to kill the server on disconnect and now im getting all sorts of indentation errors

Code:

#! /usr/bin/python
  2 import socket
  3 server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  4 server_socket.bind(("localhost", 5000))
  5 server_socket.listen(5)
  6
  7 print "TCPServer Waiting for client on port 5000"
  8
  9 while 1:
 10    client_socket, address = server_socket.accept()
 11    print "I got a connection from ", address
 12    while 1:
 13      data = raw_input ( "SEND( TYPE q or Q to Quit):" )
 14      if (data == 'Q' or data == 'q'):
 15          client_socket.send (data)
 16          client_socket.close()
 17          server_socket.close()
 18          break
 19      else:
 20          client_socket.send(data)
 21          data = client_socket.recv(512)
 22          if ( data == 'q' or data == 'Q'):
 23            client_socket.close()
 24            server_socket.close()
 25            break
 26          else:
 27            print "RECIEVED:" , data
 28

thats the code i have first error i get is line 18
File "./server.py", line 18
break
^
IndentationError: unindent does not match any outer indentation level

Berhanie 02-02-2010 07:15 PM

worked for me. maybe you have some tabs in there. check with
Code:

cat -A server.py
also, received is misspelled.


All times are GMT -5. The time now is 09:24 PM.