Sockets on Windows and Mac
Alex Martelli
aleax at mail.comcast.net
Sun Jan 8 12:46:32 EST 2006
rodmc <rodmc at userpro.com> wrote:
> I am new to Python and have been writing some socket based programmes
> on Windows (with some success), however I am unable to get them to work
> on Mac.
>
> Are there differences in the way the socket module works on Windows and
> Mac? I would appreciate any simple code samples people my have for
> creating a very basic server on Macpython, I have copied code from
> various tutorials but as yet they don't appear to work.
Assuming you mean the MacOS X which has been current, in one version or
another, for the last few years (I don't know anything about ancient
OS's such as MacOS 9 etc), I've personally tested all the socket
programming examples from the Nutshell on MacOS X 10.3 and 10.4 (Panther
and Tiger), and they do, of course, run just fine. You can download the
zipfile with all the examples of "Python in a Nutshell" from the
O'Reilly site, even if you don't own the book, and try them. Of course,
you must run a server and one or more client from different Terminal
windows -- that's about the only important (but totally obvious)
precaution you should take.
I don't think you can set the Mac's firewall to impede communication
within the localhost, but I admit I haven't tried -- so, if you have any
problem, detach your Mac from any networks and then in System
Preferences disable the firewall entirely (and make sure your Mac
doesn't erroneously believe it DOES have external networks, i.e., only
"networking" is to/from '127.0.0.1', the local host, AKA the loopback or
'lo0' interface). If you STILL have problems after that, copy and paste
the output of ifconfig, it should start something like:
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
inet 127.0.0.1 netmask 0xff000000
and also any current messages from an instance of
Applications/Utilities/Console -- as well of course as error messages
and tracebacks, if any, from your Python scripts, but I think any
problem must result from some weird issue with system settings rather
than any programming issue. Do remember to copy and paste, NOT
summarize in your own words, otherwise you may make it unfeasible for us
to help you out!
Alex
More information about the Python-list
mailing list