Python Forum
TCP server syntax error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
TCP server syntax error
#1
I'm trying to create a tcp server on python. Does anyone know why I'm receiving this syntax error despite defining 'server' earlier in the code. Is it something to do with indentations??

Attached Files

Thumbnail(s)
   
Reply
#2
I'd like to help you, but I don't use imaging software to write my code, and as such, the attached file is about as much use as a windmill on the moon, for me. Doh

If you'd like to post your code 'as code', then maybe you'll get some help.
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#3
As advised by @rob101, post the code as text, using proper BBCode tags. Posting it as image is never a good idea. That said, looking at your image - you need to familiarise yourself with the concept of scope, which is fundamental in programming. The name server is in local scope, i.e. available only inside the main() function. Probably your intention was to have the while loop inside the main() function? That brings us to next - why do you write in python interactive interpreter. That way you loose your code once the session ends. Write the code as text file with .py extension (i.e. a python module)
Also NameError and SyntaxError are two completely different errors in python.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Paramiko Server -- Exception (server): Error reading SSH protocol banner ujlain 3 4,643 Jul-24-2023, 06:52 AM
Last Post: Gribouillis
  500 Internal Server Error Flask Api on Lighttpd koklimabc 0 2,285 Apr-14-2020, 08:15 AM
Last Post: koklimabc
  python -m http.server giving invalid syntax echowit 5 7,200 May-17-2018, 02:13 PM
Last Post: echowit

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020