usman Posted June 21, 2019 Posted June 21, 2019 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 i dont get it at all, really need some help
身勝手のごくい Posted June 22, 2019 Posted June 22, 2019 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. 1
CodeExplorer Posted June 22, 2019 Posted June 22, 2019 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(): 2
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now