Sockets on Windows and Mac

R

rodmc

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.

Thanks,

rod
 
I

Irmen de Jong

rodmc said:
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.

Please elaborate on "unable to get them to work". What problems do you see?

In my experience, there is no difference with the Mac. I'm using a
mac (with OS X tiger) myself.


--Irmen
 
R

rodmc

I am on 10.3, I keep getting exceptions when it hits lines like

mySocket.bind (SERVER_IP, 2727 )
or
mySocket = socket.socket(socket.AF_NET,socket.SOCK_STREAM)

The code I am using is copied from a tutorial on a website somewhere.

Cheers,

rod
 
P

Peter Hansen

rodmc said:
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.

Aren't you basing this on the standard library modules such as
SocketServer, or extension packages like Twisted, that already do most
of the work for you? If you were, you likely wouldn't have to deal with
any such Mac-specific problems (if that's really what they are) and you
would likely save yourself a whole heck of a lot of time reinventing the
wheel too. (Note also that most people doing raw socket programming do
it wrong, which is a good reason to jump straight ahead to build on the
work of others.)

-Peter
 
R

rodmc

Hi Peter,

I am currently importing the socket library when I write the programs,
I have had no problems with it on my PC at work, but the Mac at home
steadfastly refuses to work. As for existing libraries, I am new to
Python so am kean to avoid re-inventing the wheel :)

Cheers,

rod
 
R

rodmc

Hi Peter,

I am currently importing the socket library when I write the programs,
I have had no problems with it on my PC at work, but the Mac at home
steadfastly refuses to work. As for existing libraries, I am new to
Python so am kean to avoid re-inventing the wheel :)

Cheers,

rod
 
A

Alex Martelli

rodmc said:
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
 
G

Grant Edwards

I am currently importing the socket library when I write the programs,
I have had no problems with it on my PC at work, but the Mac at home
steadfastly refuses to work.

Well, with details like that, we'll have your problem figured
out in no time!
 
P

Peter Hansen

rodmc said:
I am currently importing the socket library when I write the programs,
I have had no problems with it on my PC at work, but the Mac at home
steadfastly refuses to work.

One rule about asking for help in forums like this is to provide
adequate background detail about your environment. Generally that
includes version numbers of things. What versions of Python are you
trying to work with?

Note that the code you posted, from that tutorial, is out of date and
needs to be fixed for recent versions of Python, where the argument to
..bind() is a single tuple, not two separate arguments.

Anyway, next time please post snippets of your actual code, with the
error tracebacks *cut and pasted* right out of your terminal window, so
that you don't waste our time by making us guess what you're actually
doing. That way you'll get quick and accurate assistance and keep
everyone helping you happy. :)

-Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,276
Messages
2,571,384
Members
48,072
Latest member
FaustoBust

Latest Threads

Top