When you build and run the Java example in v. 1.1.1, it just prints some JSON stuff and then stops doing anything.
With some debugging I figured out the program keeps waiting for authorization in main().
By enabling the print() function in Client.UpdatesHandler.onResult() default case, the handler prints out many more JSON messages. Looks like message parsing/handling is out of date somewhere. Continuing digging...
Hi.
Are you running the example on Windows? Are you using cmd as a console?
Java example should work with cmd as a console on Windows, but it definitely don't work with mintty as a console.
Ok, the example works in cmd on Windows.
It doesn't work in Git Bash (MingW64 based).
Java version is 1.8.0-161.
I'm running the program with command
java -d32 -Djava.library.path=. org/drinkless/tdlib/example/Example
So the program runs in 32-bit mode. It's because compiling TdLib in 64-bit mode was not successful out of the box so I just went with 32-bit build. There were some problems with CMake settings (I built it as instructions said, though).
Could this issue with cmd vs other consoles be added into the instructions, please?
And is there some remedy for that?
Yes, I'll add a note that on Windows the example should be run from cmd. Git bash uses mintty and mintty is incompatible with Java's System.console() used in the example. Some details about why it can't be fixed on mintty side can be found here: https://github.com/mintty/mintty/issues/244. Other similar issues with mintty on Windows can be found here: https://github.com/mintty/mintty/issues/56.
To built 64-bit binary on Windows, you need to specify -A x64 to CMake. This possibly also needs to be added to README, despite it is entirely specific to CMake's MSVC generator.
Hi there. Same problem here, but in this case, running the example from Eclipse's console. I can build and run the example, but it only goes up to the test of Client.execute (I think that that's the JSON output referred by @hekkup) . Then the code enters the main loop and gets blocked. I have found that it is due the System.console() command. You can't run it inside Eclipse's console, but there are some alternatives: https://stackoverflow.com/questions/104254/java-io-console-support-in-eclipse-ide
I've fixed it substituting the System.console().readline() line by this snippet:
System.out.println("Enter command (gcs - GetChats, gc <chatId> - GetChat, me - GetMe, sm <chatId> <message> - SendMessage, lo - LogOut, q - Quit): ");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String command = null;
try {
command = bufferedReader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Using BufferedReader solves the problem. Thanks, @juananpe!
Just need to add the imports to the file:
import java.io.BufferedReader;
import java.io.InputStreamReader;
Thanks, @hikkup and @juananpe!
Most helpful comment
Hi there. Same problem here, but in this case, running the example from Eclipse's console. I can build and run the example, but it only goes up to the test of Client.execute (I think that that's the JSON output referred by @hekkup) . Then the code enters the main loop and gets blocked. I have found that it is due the System.console() command. You can't run it inside Eclipse's console, but there are some alternatives: https://stackoverflow.com/questions/104254/java-io-console-support-in-eclipse-ide
I've fixed it substituting the System.console().readline() line by this snippet: