Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String hex = "1040014116";
- StringBuilder output = new StringBuilder();
- for (int i = 0; i < hex.length(); i+=2) {
- String str = hex.substring(i, i+2);
- output.append((char)Integer.parseInt(str, 16));
- }
- System.out.println(output);
- int serverPort = 2003;
- String address = "xx.xx.xx.xx";
- try {
- InetAddress ipAddress = InetAddress.getByName(address);
- System.out.println(" IP address " + address + " and port " + serverPort);
- Socket socket = new Socket(ipAddress, serverPort);
- System.out.println("Socket ready");
- InputStream sin = socket.getInputStream();
- OutputStream sout = socket.getOutputStream();
- DataInputStream in = new DataInputStream(sin);
- DataOutputStream out = new DataOutputStream(sout);
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- String line = null;
- System.out.println("Введите данные и нажмите 'Ввод'");
- System.out.println();
- while (true) {
- line = reader.readLine();
- System.out.println("Отправка на сервер");
- out.writeUTF(line);// отправка текста
- System.out.println("Отправка: : " + line);
- out.flush(); // конец передачи
- line = in.readUTF(); // возврат текста от сервера
- System.out.println("Сервер: : " + line);
- System.out.println("Введите новую строку");
- System.out.println();
- }
- } catch (Exception x) {
- x.printStackTrace();
- }
Add Comment
Please, Sign In to add comment