Python networking refusing connections. Help!

Hi
Still at it..

My Python TCP networking code is plagued with Connection refusals. Both between machines and on localhost.
Someone said on another question that this worked for them. - and showed me windows cmd window doing it correctly.
I am trying to run the server code in IDLE alone and it is giving me connection refusals with the client...

Traceback (most recent call last):
  File "/Users/jameshancock/Desktop/deep red wars/DRWpython/Client.py", line 11, in <module>
    s.connect((host,port))          # Connect to server address
ConnectionRefusedError: [Errno 61] Connection refused
>>> Listening for connections..
SyntaxError: invalid syntax

Open in new window


It is still the code on this page here

Sorry to ask a new question, but I don't understand these connection refusals.
Is it a firewall thing?
I think IDLE may have a problem with trying to run two similar .py's at a time? Can I safely run two at a time in IDLE?
how do I start these from a console on a Mac? - so it is clearly two different Threads that don't crash one another with similar PORT usage on one Machine?
LVL 1
beavoidAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
I'm trying to run both the code you have referred to and the demo code from the Python site here https://docs.python.org/2/library/socket.html#example and so far, they don't work and the errors don't make any sense.  I'm running Python 2.6 and the demos are for 2.7 but I don't know if that makes any difference.  Also, there are typos in the code you were using.

For what it's worth, the first two demos about hostname on this page work.
0
Dave BaldwinFixer of ProblemsCommented:
I installed Python 2.7.8 and it didn't make any difference.
0
käµfm³d 👽Commented:
I don't have access to a Mac, but your code works fine on Windows:

Screenshot (Python 2.7)
It would seem that there are environmental differences between Windows and Mac. Perhaps it's the firewall, but someone with a Mac would have to confirm that.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

beavoidAuthor Commented:
Okay, thanks

What a let down ! :)
This is like saying java.awt.Frame works in JDK 1.x and not JDK 4.x and on Windows, not Mac

Dave, which example page works fine? Just on Windows?

"For what it's worth, the first two demos about hostname on this page work." Will that be what I need, to do an RTS server listening socket?

Thanks
0
Dave BaldwinFixer of ProblemsCommented:
Actually, after seeing @kaufmed's code, I realized I was doing something wrong.  So I ran the original client/server that you were using in IDLE and it worked.  In a while, I'll copy it over to my Mac (OSX 10.6) and see if it works.  I may have to install Python on that machine.
0
Dave BaldwinFixer of ProblemsCommented:
Ok, I put your original code on my MacBook Pro and it does run using Python 2.6.1.  I had to change the 'host' to the IP address of the machine (in both programs) and click on 'Ok' to allow the Server code to accept connections.  But it did run.
0
beavoidAuthor Commented:
To be sure,

My About window on IDLE says

Python Version 3.3.3  

IDLE version 3.3.3
0
Dave BaldwinFixer of ProblemsCommented:
I did upgrade to Python 2.7.8 but my MacBook Pro is from about 2006 and is running OS X 10.6.8.  On the Python site is 'demo code' for Python 3 also.  Do you have any other Python programs working?
0
beavoidAuthor Commented:
Yes
I can do all the newbie printf type stuff with data structures. I couldn't get TKinter going, but I was able to code up a decent start to a Python RTS server in UDP. I just need reliable TCP initial connections and then I'll be on my bike.
Thx
0
Dave BaldwinFixer of ProblemsCommented:
0
Dave BaldwinFixer of ProblemsCommented:
And this for Python 3.3: https://docs.python.org/3.3/library/socket.html#socket-objects  And this: http://pymotw.com/2/socket/tcp.html  I didn't get either of them working but maybe there is info you can use there.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
beavoidAuthor Commented:
Nice pages, Thanks

I don't seem to understand what ActiveTcl is. I read the description. It is not clear. Why does IDLE not come with the best tkinter automatically? Is it the only way to do windows functionality? Why is there not a simple JFrame equivalent in Python? Was Python intended to be mainly a console type language?
0
Dave BaldwinFixer of ProblemsCommented:
ActiveTcl is just a different version that the Python people seem to prefer to the Apple version.  As to the rest of your 'Why's... who knows?  These things usually come about to solve a small problem and then get used for larger ones without any particular intention or plan.
0
beavoidAuthor Commented:
So, if my IDLE says I have Tk version 8.5.9, I'm ready to go on tkinter?

For that 3.3 networking functions and methods page, thanks, but it seems strange that it says some functionality apparently is for Windows, and not Mac.
Isn't it platform independent?
Thanks
0
Dave BaldwinFixer of ProblemsCommented:
As I understand that page, if IDLE is working, already have tkinter.  I see a number of comments about Windows on that page.  I don't know of any language that is completely "platform independent".  PHP has a number or Windows-only or Linux-only extensions.  PHP sockets probably have similar limitations.
0
beavoidAuthor Commented:
Thanks

I found this page about Windows inadequacy...

(That you can only do local connections, which is also what I also discovered, btw)

It suggests using SocketServer. Does that sound valid?

here

How does this SocketServer page look below?
Dave, after, what, 3 months of plaguing you with Java TCP questions, could this be the end of it?

I found this SocketServer page here

? ?
0
Dave BaldwinFixer of ProblemsCommented:
I told you before that I never use 'localhost' because I have nothing set up to run on localhost.  I use the IP address of the machine.  

I copied your original Python (not Java) code to another machine.  I ran the server part on this machine and the client part on the other machine and they communicated just fine.  It also worked from my Mac to this machine.

The server code needs the IP address of the machine that it is running on and the firewall needs to be opened so it can receive requests from the client.  The client code needs the IP address of the machine that it is trying to contact which will be the IP address of the machine that the server code is running on.  Since it is an out-going request, it will not need the standard Windows firewall to open for it.

SocketServer may work, I don't know.
0
Dave BaldwinFixer of ProblemsCommented:
I just had another odd thing happen.  If you close the IDLE program window before the program finishes (the server program in particular), the 'socket' set up by the program persists unless you go into Task Manager and kill 'pythonw.exe'.  You get a 'socket already in use' error message.
0
beavoidAuthor Commented:
I am getting very promising results now using SocketServers here

..Thanks to all the above advice.
0
Dave BaldwinFixer of ProblemsCommented:
You're welcome, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.