0
votes
import socket, thread, time

def main():
    #server()
    #client()

def client():
    HOST = ''
    PORT = 
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((HOST, PORT))
    s.sendall('Hello, world')
    data = s.recv(1024)
    s.close()
    print 'Received', repr(data)

def server():
    HOST = ''
    PORT = 
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((HOST, PORT))
    s.listen(1)
    conn, addr = s.accept()
    print 'Connected by', addr
    while 1:
        data = conn.recv(1024)
        if not data: break
        conn.sendall(data)
    conn.close()

if name == "main": main() File "try.py", line 7 def client(): ^ IndentationError: expected an indented block

What is the problem? Please answer if it is possible.

2
You have the body of your main function commented out. - Jamie Bull

2 Answers

13
votes

Your main function has no body. That's not allowed. If you want it to do nothing, use the pass statement.

1
votes

As mentioned above you do miss the def main.

As best practice you should use this format to make sure you are in the main process when executing the main.

You should get used to write the main in the following format:

def main():
    # my code here

if __name__ == "__main__":
    main()

This will prevent the main from being executed when your script is imported as module.