Jump to content
Tuts 4 You
Sign in to follow this  
usman

HELP python syntaxError: invalid syntax

Recommended Posts

usman
Quote

 


import socket

def Main():
    host = "127.0.0.1"
    port = 5000

    s = socket.socket()
    s.bind((host, port))
    s.listen(1)
    c, addr = s.accept()
    print 'Connection From :' + str(addr)

    while True:
        data = c.recv(1024)
        if not data:
            break
        print "from connected user: "+str(data)
        data = str(data).upper()
        print "Sending" + str(data)
        c.send(data)
    c.close()

if __name__ == "__main__":
    Main()

 

 

the problem is i cannot run and getting this error

wtf.png

i dont get it at all, really need some help 

Share this post


Link to post
身勝手のごくい

Cannot see your image, code looks ok. Its python2 maybe u run it with 3?

If you run it on linux, dont use capitals on function names - ur case Main.

  • Like 1

Share this post


Link to post
CodeExplorer
def main():

Read:
https://docs.python.org/2/howto/sockets.html

https://www.tutorialspoint.com/python/python_networking.htm
From my very limited python knowledge there is a problem in the way you declare the Main Method:
https://www.guru99.com/learn-python-main-function-with-examples-understand-main.html

So instead of:

def Main():

try lower case mode:

def main():

 

  • Like 1

Share this post


Link to post
usman

thanks in advance

it works now 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...