SFS2X 2.16 with UDP and IPv6

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

wakkowarner
Posts: 3
Joined: 18 Jan 2017, 10:19

SFS2X 2.16 with UDP and IPv6

Postby wakkowarner » 07 Jul 2020, 12:17

When updating from version 2.13 , where we are listening to specific IPv4 and IPv6 addresses both for TCP and UDP with a server.xml like:

Code: Select all

<socketAddresses>
    <socket address="[IPv4]" port="9933" type="TCP"/>
    <socket address="[IPv4}" port="9933" type="UDP"/>
    <socket address="[IPv6]" port="9933" type="TCP"/>
    <socket address="[IPv6]" port="9933" type="UDP"/>
  </socketAddresses>

to version 2.16 we are getting errors on boot:

Code: Select all

Exception: java.lang.IllegalStateException
Message: UDP Port 9933 is already bound
Description: Unexpected error during Server boot. The server cannot start.
Solution: Please email us the content of this error message, including the stack trace to support[at]smartfoxserver.com
+--- --- ---+
Stack Trace:
+--- --- ---+
com.smartfoxserver.bitswarm.core.datagram.DatagramChannelCache.addChannels(DatagramChannelCache.java:27)
com.smartfoxserver.bitswarm.core.SocketAcceptor.bindUdpSocket(SocketAcceptor.java:444)
com.smartfoxserver.bitswarm.core.SocketAcceptor.bindSocket(SocketAcceptor.java:351)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.bindSockets(BitSwarmEngine.java:603)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.bootSequence(BitSwarmEngine.java:343)
com.smartfoxserver.bitswarm.core.BitSwarmEngine.start(BitSwarmEngine.java:198)
com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:312)
com.smartfoxserver.v2.Main.main(Main.java:13)

That's probably because of the switch to tomcat from jetty and tomcat trying to listen on UDP6 for all interfaces. Netstat on the server gives:

Code: Select all

udp6       0      0 [IPv4]:9933     :::*                                24143/java

If we remove the

Code: Select all

<socket address="[IPv6]" port="9933" type="UDP"/>

from the server.xml smartfox starts up just fine, but of course we don't have IPv6 with UDP then. This is for a CentOS7 server with Oracle JDK8.
Is there a solution for our problem?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS2X 2.16 with UDP and IPv6

Postby Lapo » 07 Jul 2020, 14:36

Hi,
When updating from version 2.13 , where we are listening to specific IPv4 and IPv6 addresses both for TCP and UDP with a server.xml like:

Normally this is not necessary. If you just use "0.0.0.0" for both TCP and UDP it's best as you don't have to hardcode any ip address and if you'll need to move the server it will work regardless of the network changes.

In particular for UDP since 2.16 you will need to use one listener. (you can still use multiple ones for TCP, if needed)

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
wakkowarner
Posts: 3
Joined: 18 Jan 2017, 10:19

Re: SFS2X 2.16 with UDP and IPv6

Postby wakkowarner » 07 Jul 2020, 14:49

As this is a multi homed server with several IPs we would rather not have Smartfox listen on all interfaces. Is there another option besides listening on all interfaces and using a firewall to restrict access? Can the UDP socket be restricted in any way?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS2X 2.16 with UDP and IPv6

Postby Lapo » 07 Jul 2020, 15:10

You can specify one IP address, in which case the server will just listen on that one.
I am not sure why you need more than one, considering that clients will use one address anyways (to connect, that is).

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
wakkowarner
Posts: 3
Joined: 18 Jan 2017, 10:19

Re: SFS2X 2.16 with UDP and IPv6

Postby wakkowarner » 08 Jul 2020, 06:58

Well we would still at least need one IPv6 address for clients that support IPv6 and a IPv4 address for the other clients. Which used to work with the old jetty based Smartfox 2.13. IMHO the new behavior is a bug and at least a workaround so that it's not necessary to bind to all IPv6 interfaces with a

Code: Select all

<socket address="0.0.0.0" port="9933" type="UDP"/>
or

Code: Select all

<socket address="::" port="9933" type="UDP"/>
entry in server.xml should be possible. Note that the problem only exits for UDP sockets, TCP is working just fine with dedicated IP addresses.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFS2X 2.16 with UDP and IPv6

Postby Lapo » 08 Jul 2020, 09:13

I see what you mean.
Currently this is not a bug. The new UDP implementation is more complex than the previous one, and uses a cache of Datagram channels to improve scalability. This in turn would need to be duplicated for each different UDP listeners, which is quite expensive.

As regards IPv6 ... there exists clients that can only, exclusively connect to IPv6 addresses? We have never seen this before, I think. (I might be wrong)

In any case we already have a TODO entry in our system to go back to the UDP implementation and see how to support multiple listeners.

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Stevenor and 54 guests