Python Socket Bind Error 98
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more socket.error errno 98 address already in use python about Stack Overflow the company Business Learn more about hiring developers or posting
Python Setsockopt
ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack
Socket.error Errno 98 Address Already In Use Flask
Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Python: Binding Socket: “Address already in use” up vote 38 down
Python Unbind Socket
vote favorite 10 I have a question regarding client socket on TCP/IP network. Let's say I use try: comSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) comSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) except socket.error, msg: sys.stderr.write("[ERROR] %s\n" % msg[1]) sys.exit(1) try: comSocket.bind(('', 5555)) comSocket.connect() except socket.error, msg: sys.stderr.write("[ERROR] %s\n" % msg[1]) sys.exit(2) The socket created will be bound to port 5555. The problem is that after ending the connection comSocket.shutdown(1) comSocket.close() Using wireshark, I see the python socketserver reuse address socket closed with FIN,ACK and ACK from both sides, I can't use the port again. I get the following error: [ERROR] Address already in use I wonder how can I clear the port right away so that next time I still can use that same port. comSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) setsockopt doesn't seem to be able to resolve the problem Thank you! python sockets tcp port share|improve this question edited Dec 31 '13 at 19:49 asked Jun 17 '11 at 0:12 Tu Hoang 97872235 Why does a client need a specific port? –AJ. Jun 17 '11 at 0:17 Because I have to put that into a production server, and in that server, all outgoing connections are blocked. I need to specify a specific port to the socket so that they can set up a rule on the firewalls that allows the connection to go through. –Tu Hoang Jun 17 '11 at 0:46 I suggest you copy & paste the actual code. What you wrote above has an obvious error that would prevent you from seeing the behavior you claim to have seen. This leaves readers with no idea what else you have neglected to tell us that might be ca
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about socket address already in use c hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges error: [errno 98] address already in use odoo Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. python socketserver address already in use Join them; it only takes a minute: Sign up Python [Errno 98] Address already in use up vote 53 down vote favorite 26 In my Python socket program, I sometimes need to interrupt it with ctrl-c. When I http://stackoverflow.com/questions/6380057/python-binding-socket-address-already-in-use do this, it does close the connection using socket.close() however when I try to reopen it I have to wait what seems like a minute before I can connect again. How does one correctly close a socket? Or is this intended? python sockets connection errno share|improve this question edited Feb 10 '14 at 0:49 Benjamin Gruenbaum 123k41271351 asked Dec 16 '10 at 22:24 skylerl 1,09992443 add a comment| 3 Answers 3 active oldest votes up vote 76 down http://stackoverflow.com/questions/4465959/python-errno-98-address-already-in-use vote accepted Yes, it is intended. Here you can read detailed explanation. It is possible to override this behavior by setting SO_REUSEADDR option on a socket. For example: sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) share|improve this answer answered Dec 16 '10 at 22:33 Bartosz 3,5201815 add a comment| up vote 7 down vote If you use a TCPServer, UDPServer or their subclasses in the SocketServer module, you can set this class variable (before instanciating a server): SocketServer.TCPServer.allow_reuse_address = True (via SocketServer.ThreadingTCPServer - Cannot bind to address after program restart ) This causes the init (constructor) to: if self.allow_reuse_address: self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) share|improve this answer edited Oct 12 at 17:14 Ribo 1,7371424 answered Aug 27 '14 at 14:17 dirkk0 9801018 add a comment| up vote 1 down vote -> ps -fA | grep python 501 81211 12368 0 10:11PM ttys000 0:03.12 python -m SimpleHTTPServer -> kill 81211 share|improve this answer answered Jun 13 at 13:58 ayoub laaziz 1025 This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review –Jerzyk Jun 13 at 23:48 add a comment| Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post as a guest Name
Post #1 of 6 (2930 views) Permalink Socket error 98 "Address already in use" Hi, I'm trying to make a little mp3 http://www.gossamer-threads.com/lists/python/python/836550 server / client and I'm running into a problem with the Socket error http://www.thecodingforums.com/threads/socket-error-errno-98-address-already-in-use.733361/ 98 "Address already in use". The error doesn't happen right away, I can send 3-4 commands, disconnecting and reconnecting and they work fine and then I get this error and the client can no longer connect, although the client side doesn't get any errors. Here's the relevant code: s = socket.socket(socket.AF_INET, address already socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() try: self.player(conn, addr) except: pass conn.close() s.close() del s .. and on client: HOST = '' PORT = 50025 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.connect((HOST, PORT)) Thanks! -ak -- http://mail.python.org/mailman/listinfo/python-list ak at nothere Jun17,2010,4:28PM Post #2 of 6 (2875 views) Permalink Re: Socket error 98 "Address already in use" [In reply to] address already in On 06/17/2010 07:21 PM, AK wrote: > Hi, I'm trying to make a little mp3 server / client and I'm running into > a problem with the Socket error 98 "Address already in use". The error > doesn't happen right away, I can send 3-4 commands, disconnecting and > reconnecting and they work fine and then I get this error and the client > can no longer connect, although the client side doesn't get any errors. > Here's the relevant code: > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.bind((HOST, PORT)) > s.listen(1) > conn, addr = s.accept() > try: self.player(conn, addr) > except: pass > conn.close() > s.close() > del s > > > .. and on client: > > > HOST = '' > PORT = 50025 > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) > s.connect((HOST, PORT)) > > > Thanks! -ak I forgot to add that I'm on Ubuntu 9.10 and using python 2.6. -ak -- http://mail.python.org/mailman/listinfo/python-list invalid at invalid Jun17,2010,5:19PM Post #3 of 6 (2875 views) Permalink Re: Socket error 98 "Address already in use" [In reply to] On 2010-06-17, AK <
in use" when i try to open a socket that got closed before with close(). How come close() doesn't close the socket properly? My socket code : s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) s.listen(1) .... .... .... while loop: conn, addr = s.accept() while conn and loop: .... .... .... conn.close() Shouldn't that clean it all up properly? Thanks for hints & suggestions! Ron cerr, Sep 15, 2010 #1 Advertisements Thomas Jollans Guest On Wednesday 15 September 2010, it occurred to cerr to exclaim: > Hi There, > > I get a socket error "[Errno 98] Address already in use" when i try to > open a socket that got closed before with close(). How come close() > doesn't close the socket properly? > My socket code : > > s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > s.bind((host, port)) > s.listen(1) > ... > ... > ... > while loop: > conn, addr = s.accept() > while conn and loop: > ... > ... > ... > conn.close() > > Shouldn't that clean it all up properly? `s` is still listening? Thomas Jollans, Sep 15, 2010 #2 Advertisements Guest -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 El 15/09/2010 20:58, Grant Edwards escribió: > On 2010-09-15, cerr <> wrote: > >> I get a socket error "[Errno 98] Address already in use" when i >> try to open a socket that got closed before with close(). How >> come close() doesn't close the socket properly? My socket code : >> >> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >> s.bind((host, port)) s.listen(1) ... ... ... while loop: conn, >> addr = s.accept() while conn and loop: ... ... ... conn.close() > > At what line does the error occur? > > To what does the phrase "open a socket" refer? > > Have you tried the usual solution of setting the SO_REUSEADDR > option on the socket before calling bind? > > http://www.google.com/search?q=socket+'address+already+in+use' > Maybe, you have any other proccess in your system using your listen port, for example apache... - -- _ _ _ _ _ _ _ _ _ _ _ Jose Ignacio Palacios Ortega /_ _/ / / / _ / / _ / Telf: +34 637 058 813 / / / / / /_ / / / / / / Correo-e: _ / / / / / _ _ _/ / / / / Msn: / /_ / / / / / / / /_/ / ID firma PGP: 0x0EB87E48 \ _ _ / /_/ /_