Closed ricardoboss closed 7 years ago
First of all (I doubt that's what causes your problem, but I can't exclude the possibility):
TS3Config#setHost
only accepts the host address without a port. config.setHost("localhost")
is valid, config.setHost("localhost:10011")
isn't. To specify the query port you'll have to use TS3Config#setQueryPort
.
But I don't think this problem is caused by you incorrectly using this API. I think it's much more likely it's some kind of java / network configuration problem. Here's what I've been able to dig up:
First of all, I've never seen the SocketImpl TwoStacksPlainSocketImpl
"in the wild", usually it's SocksSocketImpl
. Looking up the source for TwoStacksPlainSocketImpl
, the class comment explains that
This class defines the plain SocketImpl that is used for all
Windows version lower than Vista. It adds support for IPv6 on
these platforms where available.
This also reaffirms my suspicion that you've been trying to run our API on a strange OS; turns out it's not weird but probably just old :smile:
Some more google-fu led me to this StackOverflow question. The top comment suggests that this is an IPv4 vs IPv6 problem and that this can be fixed by adding -Djava.net.preferIPv4Stack=true
as a VM argument. Seeing how TwoStacksPlainSocketImpl
specifically mentions its IPv6 behavior, I think this would be a good first thing to try.
If this fixes your issue, it might also be worth investigating your IPv6 settings and maybe disabling IPv6 in your network adapter settings, because these connection issues could also affect other non-Java applications.
If this did not fix your issue, I'd suggest you next try running some sample code using this API outside of BungeeCord. It could very well be there there are components of Bungee that interfere with plugins randomly opening connections (security concerns and whatnot).
I actually tried to add the VM arg. Will try to deactivate IPv6 later.
And the OS I'm using is not that old... It's Windows 10.
It's Windows 10
The documentation is lying to me! 😛
But then I really don't know why Java would choose that implementation for the Socket. I'll have to investigate that tomorrow. It's a bit too late for that kinda thing now ^^
Soo I tested both, the VM args and deativating my IPv6 adapter but I still get the same error. I even updated my java jre and sdk to the latest releases.
Hmm, I have two more things you could test:
First of all, try using 127.0.0.1
instead of localhost.
Second, try running your code outside of BungeeCord and / or on another computer.
@MCMainiac Have you had any success dealing with this problem? Or should we try some more troubleshooting?
Sorry for not responding for so long, but I was busy irl :D
I'll have a look at your ideas and share the results on this thread.
Wow.
Please, kill me now.
There was an error while reading out the port from the config.
I'm sorry... But at least I found another bug: #132
Please don't flame me ._.
I'll leave this open, so you (@Firedroide) can add somehting if you want to. For me, this case is closed. Everything is working fine while connecting now.
@Firedroide Maybe you should add some kind of validation for the host and port. Host: a-z1-9.- Port: 0 - 65535
If you haven't done that already...
I feel like that is unnecessary. Opening a socket with an invalid host or port will already throw an exception.
2016-08-29 23:20 GMT+02:00 mohe2015 notifications@github.com:
@Firedroide https://github.com/Firedroide Maybe you should add some kind of validation for the host and port. Host: a-z1-9.- Port: 0 - 65535
If you haven't done that already...
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/TheHolyWaffle/TeamSpeak-3-Java-API/issues/128#issuecomment-243260236, or mute the thread https://github.com/notifications/unsubscribe-auth/AAwFyt1ndviHg14UTCjkWI1_84A9XvEeks5qk00ugaJpZM4Jj-32 .
@TheHolyWaffle I agree with you on incorrect host addresses, but not on incorrect ports.
Any port < 0 || port > 65535 will fail with
Exception in thread "main" java.lang.IllegalArgumentException: port out of range:65536
Which is great, anybody can figure out what's wrong here. However, port 0 (which I think caused this exception) is usually used to let the host decide to use a random port. Of course, this doesn't work for when you need to connect to one specific port. Even worse, it fails with this message
java.net.ConnectException: connect: Address is invalid on local machine, or port is
not valid on remote machine
and as you can see, I have failed miserably at diagnosing what's causing this issue.
I think adding a simple range check to TS3Config in setQueryPort
is reasonable.
@MCMainiac I hope my deduction that this was caused by port 0 was correct.
I'll get to #132 as soon as I can. I already know what's causing this; and the proper fix will take some time.
It's caused by us trying to shut down properly when we failed to connect. Unfortunately, this currently just calls TS3Query#exit, which also tries to send a quit
command to tell the server that we're done. You can already see why this will fail 😛
I'll need to really clean up how reconnecting is handled, which will also fix this issue.
However, this issue will currently only occur if the initial connection attempt fails, so it's not really a critical issue. I'll get to it as soon as I can, but I'd rather take my time than creating a hotfix that has numerous other issues.
@rogermb That's actually true! Since there where errors in reading out the port number from a configuration file, port 0 was used.
@rogermb As you can see, I added a pull request that fulfills your idea of adding a simple range check.
Range check added in dd428cbdff43232c83e7a8fdf2fe2b7a91c3db7b.
Hi there!
I get this ConnectException (or TS3ConnectionFailedException) when trying to connect with 'localhost:10011':
I also googled a bit and it seems that this is neither my fault (the plugin's fault) or a configuration error.