Recent

Author Topic: Problem with sockets  (Read 2090 times)

cappe

  • Jr. Member
  • **
  • Posts: 97
Problem with sockets
« on: January 22, 2018, 01:40:38 pm »
I have a problem with linux. If I launch a http server application and I close it suddenly and try to re-launch it immediately I get this error:
could not bind socket.
After some time it gives me the opportunity to re-launch the application.
Is there a way to immediately free the socket after the application is blocked?


rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Problem with sockets
« Reply #1 on: January 22, 2018, 01:44:28 pm »
Some code would be helpful.

Are you closing the server correctly in code?
Which components did you use?

(so in other words, some code which reproduces this)

Thaddy

  • Hero Member
  • *****
  • Posts: 9152
Re: Problem with sockets
« Reply #2 on: January 22, 2018, 01:47:43 pm »
Since the OS - not your application - needs to release the sockets, use a timeout/pause of about a second.
There is not much you can do about it, I am not aware of a time-out config option for the kernel module or the daemon.
« Last Edit: January 22, 2018, 01:49:39 pm by Thaddy »
also related to equus asinus.

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7495
Re: Problem with sockets
« Reply #3 on: January 22, 2018, 01:50:52 pm »
While Thaddy is right in principle, incorrect shutting down of the application (not calling fpshutdown or releasing handles) might make the effect worse (more often or longer).

If it is single seconds, it might not be fixable, if it is longer, check your shutdown code.

cappe

  • Jr. Member
  • **
  • Posts: 97
Re: Problem with sockets
« Reply #4 on: January 22, 2018, 02:09:50 pm »
This is how an access violation occurred in the application. The application closes but the port is not released immediately.
Or if, during execution by lazarus in debugger of the web server, block execution, the port is not released immediately but after a two minutes.
Is there a way to immediately release the port?
It is not a problem of component or anything else, it is a linux problem. The waiting time is about two minutes
« Last Edit: January 22, 2018, 02:17:19 pm by cappe »

rvk

  • Hero Member
  • *****
  • Posts: 3842
Re: Problem with sockets
« Reply #5 on: January 22, 2018, 03:06:59 pm »
Is there a way to immediately release the port?
Yes, there might be.
But you haven't supplied any code or clue as to how you create the server.
So we can't say for sure how.

If you application ends with an access violation you should fix that first.
And when debugging your program, you should always let it run to its end, otherwise the port might also not be closed properly.