lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Tjis.

you will have to close the first socket before trying to reuse the address with the second socket.
The "reuseaddr" option tell sthe OS to allow to bind to the address immediately again. Without this, the address is blocked for the (estimated) time that any packet for the address is still strolling around in the internet.

--
Oliver

Am 04.12.2015 um 19:45 schrieb Thijs Schreijer:

This code;

 

local socket = require("socket")
local PORT = 30000

local server1, server2

print (socket._VERSION)
server1=socket.tcp()
assert(server1:setoption('reuseaddr', true))
assert(server1:bind("*", PORT))
assert(server1:listen())

server2=socket.tcp()
assert(server2:setoption('reuseaddr', true))
assert(server2:bind("*", PORT))
assert(server2:listen())

 

runs fine on Windows, yet on Linux (Debian 7, WM ware image) the second `bind` (for server2) fails with a "socket already in use" error. Despite the 'reuseaddr' socket option.

 

Anyone seen this and knows how to resolve it?

 

any help is appreciated.

Thijs

 

(testing a server, which involves a lot of tests quickly stopping and starting the server. The abandonned sockets are sometimes not available again before the server restarts, which makes tests fail in an unpredictible manner)