[Tutor] Socket Programming HOWTO doesn't work!
Patrick Kirk
patrick@kirks.net
Mon Jun 23 18:14:28 2003
Jeff Shannon wrote:
[...]
>
> Keep in mind, also, that when you run this script, that process will be
> tied up listening on the socket. This means that if you run it from
> within PythonWin or IDLE, the interpreter will appear to be "locked up"
> -- in fact, it's just waiting for something to come in on the socket.
> You may want to open a separate command (DOS) window to run this in, so
> that you'll still be able to access the IDE while it's running.
[...]
Still doesn't work.
import socket
#create an INET, STREAMing socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and a well-known port
serversocket.bind((socket.gethostname(), 8888))
#become a server socket
serversocket.listen(5)
When I try it on windows I get this:
Traceback (most recent call last):
File
"C:\Python22\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py",
line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\patrick\Desktop\p2pdev\simple.py",
line 1, in ?
import socket
File "socket.py", line 72, in ?
errorTab[10004] = "The operation was interrupted."
File "C:\Python22\lib\SocketServer.py", line 273, in ?
class TCPServer(BaseServer):
File "C:\Python22\lib\SocketServer.py", line 316, in TCPServer
address_family = socket.AF_INET
AttributeError: 'module' object has no attribute 'AF_INET'
On Linux I get this:
patrick@enterprise /opt/data $ python simple.py
patrick@enterprise /opt/data $
but
patrick@enterprise /opt/data $ nmap -p 8888 localhost
Starting nmap 3.27 ( www.insecure.org/nmap/ ) at 2003-06-23 23:10 BST
The 1 scanned port on localhost (127.0.0.1) is: closed
Nmap run completed -- 1 IP address (1 host up) scanned in 0.318 seconds
patrick@enterprise /opt/data $
So something is still failing badly here.
Could you try this code on your machine please? I need a sanity check!
--
Best regards,
Patrick Kirk
Mobile: 07876 560 646