package de.erich.railcontrol; import java.io.*; import java.net.*; class CommunicationClient { String sentence; String modifiedSentence; Socket clientSocket; InputStreamReader isr; BufferedReader inFromStdIn; DataOutputStream outToServer; boolean connected; public CommunicationClient() { Thread thread = new Thread(new Runnable() { @Override public void run() { String ip; int port; isr = new InputStreamReader(System.in); inFromStdIn = new BufferedReader(isr); if(MyActivity.PlaceholderFragment.ip_selector.isChecked()) { System.out.println("Online"); if(ParseLoksConfiguration.ip == null || ParseLoksConfiguration.port == 0) { ip = "192.168.4.29"; port = 4303; } else { ip = ParseLoksConfiguration.ip; port = ParseLoksConfiguration.port; } } else { System.out.println("Default"); ip = "192.168.4.24"; port = 6789; } System.out.println(ip + " " + port); try { clientSocket = new Socket(ip, port); System.out.println("Verbunden"); connected = true; } catch (IOException e) { e.printStackTrace(); connected = false; } } }); thread.setPriority(1); thread.start(); } public void sendMessage(String message) throws IOException { System.out.printf("Enter: "); outToServer = new DataOutputStream(clientSocket.getOutputStream()); //BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); sentence = message; outToServer.writeBytes(sentence + '\n'); //modifiedSentence = inFromServer.readLine(); System.out.println("FROM SERVER: " + modifiedSentence); } public void killClient() throws IOException { System.out.println("Kill Client"); sendMessage("." + "\n"); clientSocket.close(); System.out.println("CLient killed"); } }