Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java example not working properly in v. 1.1.1 (in non-cmd consoles) [solved] #141

Closed
hekkup opened this issue Mar 12, 2018 · 6 comments
Closed

Comments

@hekkup
Copy link
Contributor

hekkup commented Mar 12, 2018

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...

@levlam
Copy link
Contributor

levlam commented Mar 12, 2018

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.

@hekkup
Copy link
Contributor Author

hekkup commented Mar 13, 2018

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?

@hekkup hekkup changed the title Java example not working properly in v. 1.1.1 Java example not working properly in v. 1.1.1 (in non-cmd consoles) Mar 13, 2018
@levlam
Copy link
Contributor

levlam commented Mar 13, 2018

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: mintty/mintty#244. Other similar issues with mintty on Windows can be found here: mintty/mintty#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.

@juananpe
Copy link

juananpe commented Mar 14, 2018

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();
}

@hekkup
Copy link
Contributor Author

hekkup commented Mar 15, 2018

Using BufferedReader solves the problem. Thanks, @juananpe!
Just need to add the imports to the file:

import java.io.BufferedReader;
import java.io.InputStreamReader;

@hekkup hekkup changed the title Java example not working properly in v. 1.1.1 (in non-cmd consoles) Java example not working properly in v. 1.1.1 (in non-cmd consoles) [solved] Mar 15, 2018
hekkup added a commit to hekkup/td that referenced this issue Mar 15, 2018
…dded more info about building Java example.
hekkup added a commit to hekkup/td that referenced this issue Mar 20, 2018
…dded more info about building Java example.
levlam pushed a commit that referenced this issue Mar 20, 2018
…146)

* Changed Console to BufferedReader in Java example, fixes #141. Added more info about building Java example.
@levlam
Copy link
Contributor

levlam commented Mar 20, 2018

Thanks, @Hikkup and @juananpe!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants