There is a program on python. I listen to a socket (I run from under the root). When you first start everything runs smoothly. At runtime, the program crashes. And I can't listen to the socket a second time. The system says the port is busy. Ie, probably, a socket is hanging somewhere in the background.
Probably, I somehow incorrectly close the socket. close() is not a solution. Probably, it somehow needs to be deleted, or something else to do with it.
Code:
#! /usr/bin/env python # -*- coding: utf-8 -*- import socket print("python: start") # Сервер для браузера print('python: Test 0') sock = socket.socket() sock.bind(("127.0.0.1", 8080)) # Падает здесь Mistake:
python: start python: Test 0 Traceback (most recent call last): File "/mapsfullsearch/src/estimation/main.py", line 12, in <module> sock.bind(("127.0.0.1", 8080)) File "/usr/lib/python2.7/socket.py", line 228, in meth return getattr(self._sock,name)(*args) socket.error: [Errno 98] Address already in use ^CMakefile:130: recipe for target 'estimation' failed make: *** [estimation] Interrupt
netstat -na | grep :8080netstat -na | grep :8080after completion of the program. It is quite possible that you will see suspended connections in the state, most likely FIN_WAIT. Until all such "connections" disappear, opening the port again will not work. close () closes the listening socket, but if connections were opened (they have their own sockets), then the parties must exchange closing packets (FIN), and if all connections were not correctly closed and they were not applied (the actual closure occurs after some time) and FIN will not be exchanged, timeouts will be expected - Mikeshutdown(socket, SHUT_RDWR)to reset all buffers and send FIN - Mikesock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)- jfssocket.close(). But this does not solve the problem of an emergency interruption by the userKeyboardInterrupt.netstat -na | grep :8080netstat -na | grep :8080does not help. If you look at it throughnc, then ok. The port is used. But notnetstat. - hedgehogues