Overview
Features
Download
Documentation
Community
Add-Ons & Services

Setting socket options on a ServerSocket before bind()

Please post support and help requests here.

Setting socket options on a ServerSocket before bind()

Postby emilles » 14 May 2012, 18:31

I have a bit of code that makes use of the ServerSocket. In order to lock down the use of the local port, I'm trying to set the SO_EXCLUSIVEADDRUSE socket option. However, ServerSocket doesn't appear to allow options to be set before calling bind(). This is because the socket is not initialized until the bind() call. DatagramSocketImpl provides an example of initializing the sockfd in the constructor, which allows for setting socket options before bind.

Is there a way to set options on a ServerSocket before bind() with the current library? Or will I need to wait for a fix?

Code: Select all
      ServerSocket serverSocket;
      serverSocket.setNoDelay(true);
      // ensure bind will provide exclusive access to port if successful
      serverSocket.setOption(SOL_SOCKET, SO_EXCLUSIVEADDRUSE, TRUE);
      serverSocket.bind(port);
      serverSocket.listen();
emilles
 
Posts: 1
Joined: 14 May 2012, 18:23

Return to Support

Who is online

Users browsing this forum: No registered users and 2 guests