Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SocketManager {
- static Socket i3;
- static Boolean i4 = false;
- static String i5;
- public static String i1(final Properties i1, final String i2) {
- try {
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- i3 = new Socket();
- i3.setSoTimeout(4000);
- i3.connect(new InetSocketAddress(i1.getProperty("hostIp"), 5500), 4000);
- String i6 = i1.getProperty("username") + System.lineSeparator() + i1.getProperty("password");
- if (i2 != null) {
- i6 += System.lineSeparator() + i2;
- }
- BufferedWriter i7 = new BufferedWriter(new OutputStreamWriter(i3.getOutputStream()));
- i7.write(i6);
- i7.flush();
- //=== ВОТ ЭТА СТРОЧКА ВЫЛЕТАЕТ @
- i5 = new BufferedReader(new InputStreamReader(i3.getInputStream())).readLine();
- //===
- } catch (Exception e1) {
- Log.d("", e1.toString());
- i5 = null;
- }
- i4 = true;
- return;
- }
- }).start();
- while (!i4) {
- }
- i3 = null;
- return i5;
- } catch (Exception e1) {
- return null;
- }
- }
- }
- Properties i1 = new Properties();
- // Загружаю файл с логином и паролем. Его содержимое:
- // hostIp = мой IP-адрес
- // username = user
- // password = user
- i1.load(new FileInputStream("file.properties"));
- String i2 = "мой запрос на сервер";
- // Получаю и показываю ответ от сервера
- Toast.makeText(this, "Ответ сервера следующий:" + System.lineSeparator() + SocketManager.i1(i1, i2), Toast.LENGTH_LONG).show();
- public Void i1() {
- String i1 = "";
- // 'this.i1' это 'myServerSocket.accept()'
- BufferedReader i11 = new BufferedReader(new InputStreamReader(this.i1.getInputStream()));
- while (true) {
- String i2 = i11.readLine();
- if (i2 == null) {
- break;
- } else {
- i1 += System.lineSeparator() + i2;
- }
- }
- i1 = i1.substring(System.lineSeparator().length(), i1.length());
- System.out.println(i1);
- String[] i2 = i1.split(System.lineSeparator());
- // И тут определяем, что надо приложению
- if (i2[1].equals("команда 1") {
- i2("user".getBytes());
- } else {
- i2("false".getBytes());
- }
- return null;
- }
- private Void i2(byte[] i1) throws Exception {
- if (this.i1.isConnected() && !this.i1.isClosed()) {
- OutputStream i2 = this.i1.getOutputStream();
- i2.write(i1);
- i2.flush();
- }
- return null;
- }
Add Comment
Please, Sign In to add comment