Python Socketserver Socket.error Errno 98 Address Already In Use
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
Socket.error Errno 98 Address Already In Use Python
site About Us Learn more about Stack Overflow the company Business Learn socket.error errno 98 address already in use flask more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question
Error: [errno 98] Address Already In Use Odoo
x Dismiss Join the Stack Overflow Community Stack 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: return getattr(self._sock,name)(*args) socket.error: [errno 98] address already in use Binding Socket: “Address already in use” up vote 38 down 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. oserror: [errno 98] address already in use flask The problem is that after ending the connection comSocket.shutdown(1) comSocket.close() Using wireshark, I see the 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 err
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings
Python Allow_reuse_address
and policies of this site About Us Learn more about Stack Overflow python socketserver address already in use the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation
Python Close Socket
Tags Users Badges 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. Join them; http://stackoverflow.com/questions/6380057/python-binding-socket-address-already-in-use it only takes a minute: Sign up socket.error: [Errno 48] Address already in use up vote 61 down vote favorite 34 I'm trying to set up a server with python from mac terminal. I navigate to folder location an use: python -m SimpleHTTPServer But this gives me error: socket.error: [Errno 48] Address already in use I had previously open a http://stackoverflow.com/questions/19071512/socket-error-errno-48-address-already-in-use connection using the same command for a different website in a different location in my machine. python simplehttpserver share|improve this question edited Feb 18 '15 at 0:19 asked Sep 28 '13 at 20:48 irm 49531225 1 Kill the other process or run this one with a different port: python -m SimpleHTTPServer 8081 –Blender Sep 28 '13 at 20:50 add a comment| 4 Answers 4 active oldest votes up vote 131 down vote accepted You already have a process bound to the default port (8000). If you already ran the same module before, it is most likely that process still bound to the port. Try and locate the other process first: $ ps -fA | grep python 501 81651 12648 0 9:53PM ttys000 0:00.16 python -m SimpleHTTPServer The command arguments are included, so you can spot the one running SimpleHTTPServer if more than one python process is active. You may want to test if http://localhost:8000/ still shows a directory listing for local files. The second number is the process number; stop the server by sending it a s
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 http://stackoverflow.com/questions/17780291/python-socket-error-errno-98-address-already-in-use about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack https://brokenbad.com/address-reuse-in-pythons-socketserver/ 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 socket.error: [Errno 98] Address already in use [closed] up vote address already 12 down vote favorite 2 when i setup application.py, it shows that socket.error: [Errno 98] Address already in use. Traceback (most recent call last): File "application.py", line 121, in
to for a proof of concept. It's basically a small TCP server in python. After creating a small skeleton using SocketServer, I found that the server it self works fine with no problem. However, if I try to stop and start the server again to test any modifications, I get a random "socket.error: [Errno 98] Address already in use" error. This happens only if a client has already connected to the server. Checking with netstat and ps, I found that although the process it self is no longer running, the socket is still listening on the port with status "TIME_WAIT". Basically the OS waits for a while to make sure this connection has no remaining packets on the way. My good friend mux mentioned that I should probably set the socket option "SO_REUSEADDR" to avoid this issue. The man socket(7) says about this: SO_REUSEADDR Indicates that the rules used in validating addresses supplied in a bind(2) call should allow reuse of local addresses. For AF_INET sockets this means that a socket may bind, except when there is an active listening socket bound to the address. When the listening socket is bound to INADDR_ANY with a specific port then it is not possible to bind to this port for any local address. Argument is an integer boolean flag. When using the pure socket module, you can simply set this option using: import socket
s = socket.socket() s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) However, you don't need to this in SocketServer. SocketServer.TCPServer allows you to set by setting a simple variable. Here is a working example: #! /usr/bin/env python import socket import SocketServer class MyServer(SocketServer.StreamRequestHandler): def handle(self): self.wfile.write("Hi! I am echo!\n") while True: data = self.rfile.readline().strip() if not data: break