[Tutor] python sockets

Alan Gauld alan.gauld at btinternet.com
Wed Jun 11 09:17:48 CEST 2014


On 11/06/14 00:08, Jon Engle wrote:
> Ok, so when I run the code it immediately terminates and never 'listens'

This has nothing to do with your immediate problem but...

> ***Code***
>
>    #!/usr/bin/python           # This is server.py file
>      from socket import *      #import the socket library
>      import thread#import the thread library
>
>      startingPort=input("\nPlease enter starting port: ")
>      startingPort=int(startingPort)


You said you were using Python 2.7.
Do not use input() in Python v2 use raw_input() instead.
Especially since you are using int() to convert the data anyway.

v2 input() evaluates whatever the user types which could
be damaging code (whether deliberate or inadvertent).
v2 input() is so dangerous it was removed from v3 and
raw_input renamed as input. (Which has just created lots
of confusion IMHO!)

>      def setup(PORT):
> ##let's set up some constants
> HOST = ''    #we are the host

BTW I'm still losing nearly all indentation on your posts.
Are you posting in plain text? Nobody else is complaining
so it might just be my reader that's barfing on it...


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos



More information about the Tutor mailing list