How to reuse AWS socket?

Viewed 96

I am using an AWS webserver, which is being polled by some other script. The problem is that when I start the server twice in a few seconds (with requests of a client in between), the server fails to start again, saying:

raised AWS.NET.SOCKET_ERROR : Bind : [98] Address already in use

There is this old thread that suggests there may be a reuse_address option, either in a ini file or as a direct parameter, but says that that also does not work.

Perhaps there is some way to force the OS to abandon the socket?

1 Answers

You need to call AWS.Config.Set.Reuse_Address (Config, True); or set it in the AWS ini file.

For example:

with AWS.Config;
with AWS.Config.Set;
(...)
declare
   HTTP_Server : AWS.Server.HTTP;
   AWS_Config      : AWS.Config.Object := AWS.Config.Default_Config;
begin
   AWS.Config.Set.Reuse_Address (AWS_Config, True);
   AWS.Config.Set.Server_Port (AWS_Config, 80);
   AWS.Server.Start (HTTP_Server, Callback => Respond'Unrestricted_Access, Config => AWS_Config);
(...)
Related