[Tutor] Socket connection refused

Nick Lunt nick at javacat.f2s.com
Mon Feb 23 14:23:09 EST 2004


Error nr 10061 seems to indicate that there is too much load on the
server, and the recommended fix is to increase the timeout, but that is
when applied to SMTP/HTTP but I would expect it to be the same for all
IP based servers.

I have done the same server/client program as you a couple of weeks ago,
I created it on linux, then emailed it to my work and ran it fine on my
win2k box there, so I doubt it's a windows issue.

I have had problems with py2exe on windows and linux tho even tho the
programs were fine. I still haven't got my head around py2exe yet, I
suspect it's more complicated than I think and Im too busy learning
python to bother with it at the moment ;)

Have you tried running the server and client from the windows command
prompt ? It would be interesting to know how that goes.

Cheers
Nick.


On Mon, 23 Feb 2004 20:11:55 GMT  "Djoumy . " <deadviannou at caramail.com>
wrote:

>  Since it's only a small test program there are bugs for sure in my
> app. Anyway thanks for your help. If it works under your Linux, can
> the problem be coming from my Windows XP ? 
> 
> Djoum's
> 
> 
> ------- Message original ------- 
> De: Nick Lunt <nick at javacat.f2s.com> Date: Mon, 23 Feb 2004 19:00:49 +0000 
> Sujet: Re: [Tutor] Socket connection refused 
> 
> 
> Hi there,
> 
> I'm also new at python but I copied/pasted your source code and it ran
> fine after I'd sorted out the formatting, but I suspect that was
> because of my email client.
> 
> Anyway it runs on linux ok, the only issue I found was that when
> connecting, then clicking on the OK button on the 'Hello World'
> message I get the following TkDialog up "Can't connect to the server
> 127.0.0.1 EISCONN"
> 
> Sorry I can't be of anymore help.
> 
> Cheers
> Nick.
> 
> 
> On Mon, 23 Feb 2004 19:09:13 GMT  "Vianus le Fus "
>  wrote:
> 
> > Hello,
> > I'm a newbie to python so please don't be too hard with me :)
> > I'm encountering problems using socket connections in my programs.
> > My goal is to create a small chat program so I begin with the
> > beginning : two really small apps, one for the server and one for
> > the client. The server is here to listen to one port and to resend
> > its own data to the client that's connected to the port.
> > 
> > I have found two ways to test this : I compile the server with
> > py2exe and launch it, then I can run the client either running the
> > module under IDLE or compiling it with py2exe. And there's my
> > problem : it works under IDLE (connection is set and the client
> > receives its own data) but connection fails when using the exe
> > client.... it says"error 10061 : Connection refused". I don't have
> > any firewall nor other running programs that could block the socket,
> > I really don't understand what's the difference using py2exe or not
> > !!
> > 
> > Please does someone know why the first method works and not the
> > other?
> > 
> > -----------------------------------------------------
> > Serveur.py
> > -----------------------------------------------------
> > import socket
> > 
> > HOST = '127.0.0.1'
> > PORT = 50007
> > 
> > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> > s.bind((HOST, PORT))
> > s.listen(1)
> > conn, addr = s.accept()
> > print 'Connected by', addr
> > while 1:
> >     data = conn.recv(1024)
> >     if not data: break
> >     conn.send(data)
> > conn.close()
> > 
> > 
> > 
> > -----------------------------------------------------
> > Client.py
> > -----------------------------------------------------
> > import errno
> > import socket
> > from Tkinter import *
> > import tkMessageBox
> > 
> > class Application(Frame):
> >     def __init__(self, master=None):
> >         Frame.__init__(self, master)
> >         
> >         self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> >         self.connected = 0
> >         self.data = ''
> >         
> >         self.pack()
> >         self.createWidgets()
> > 
> >         
> >     def createWidgets(self):
> >         self.btn_quit = Button(self)
> >         self.btn_quit["text"] = "QUIT"
> >         self.btn_quit["fg"]   = "red"
> >         self.btn_quit["command"] =  self.end
> > 
> >         self.btn_quit.pack({"side": "left"})
> > 
> >         self.btn_connect = Button(self)
> >         self.btn_connect["text"] = "Connect",
> >         self.btn_connect["command"] = self.connect
> > 
> >         self.btn_connect.pack({"side": "right"})
> > 
> > 
> >     def connect(self) :
> >         try:
> >             self.s.connect(('127.0.0.1', 50007))
> >             self.connected = 1
> >             
> >         except socket.error, msg:
> >             tkMessageBox.showinfo(title='Connexion error',
> >             message='Can\'t connect \
> > to the server 127.0.0.1' + '\n' + str(errno.errorcode[msg[0]]))
> > 
> >         if self.connected == 1 :
> >             self.s.send('Hello, world')
> >             self.data = self.s.recv(1024)
> >             print 'Received', str(self.data)
> >             tkMessageBox.showinfo(title='Data received !!',
> >             message=str(self.data))
> > 
> > 
> >     def end(self) :
> >         self.s.close()
> >         self.quit()
> > 
> > 
> > # MAIN
> > app = Application()
> > app.mainloop()
> > -----------------------------------------------------
> > 
> > Plus simple, plus fiable, plus rapide : découvrez le nouveau
> > Caramail- http://www.caramail.lycos.fr
> > 
> > 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
> Plus simple, plus fiable, plus rapide : découvrez le nouveau Caramail
> - http://www.caramail.lycos.fr
> 
> 



More information about the Tutor mailing list