Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void sendCmd(String cmd) {
- String infoToSend = cmd;
- try {
- socket = new Socket(hostname, port);
- System.out.println("Trying to send: " + com.sun.org.apache.xml.internal.security.utils.Base64.encode(infoToSend.getBytes()));
- out = new DataOutputStream(socket.getOutputStream());
- out.writeBytes(com.sun.org.apache.xml.internal.security.utils.Base64.encode(infoToSend.getBytes()));
- out.flush();
- System.out.println("Socket is flushed");
- System.out.println("Waiting for Data");
- InputStream is = socket.getInputStream();
- System.out.println("Trying to get data");
- BufferedReader input = new BufferedReader(
- new InputStreamReader(is)
- );
- String line;
- while((line = input.readLine()) != null) {
- System.out.println(line);
- }
- socket.close();
- } catch (IOException e) { e.printStackTrace(); }
- }
- public void run() {
- System.out.println("Got Connection");
- try {
- BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- out = new DataOutputStream(socket.getOutputStream());
- String response;
- System.out.println("Response:");
- String decode = "";
- while ((response = in.readLine()) != null) {
- try {
- decode = new String(Base64.decode(response));
- } catch (Base64DecodingException e) {
- e.printStackTrace();
- }
- }
- System.out.println("Decoded: " + decode);
- out.writeBytes("We got your message!");
- out.flush();
- out.close();
- } catch (IOException e) { System.out.println("Fail"); e.printStackTrace(); }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement