Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static boolean connect2Pool(String SERVER, int PORT)
- {
- String message1 = "{"id":1,"method":"mining.subscribe","params":[]}";
- String authorizemessage = "{"params": ["" + USERNAME + "." + WORKER + "", "" + PASSWORD + ""], "id": 2, "method": "mining.authorize"}";
- boolean result = false;
- DataInputStream is;
- DataOutputStream os;
- try
- {
- InetAddress address = InetAddress.getByName(SERVER);
- System.out.println("Atempting to connect to " + address.toString() + " on port " + PORT + ".");
- // connect
- Socket socket = new Socket();
- socket.connect(new InetSocketAddress(SERVER, PORT));
- is = new DataInputStream(socket.getInputStream());
- os = new DataOutputStream(socket.getOutputStream());
- PrintWriter pw = new PrintWriter(os);
- pw.println(message1); //connect
- pw.flush();
- //read response
- BufferedReader in = new BufferedReader(new InputStreamReader(is));
- JSONObject json = new JSONObject(in.readLine());
- if(!json.has("result")) {
- System.out.println("no reult");
- result=false;
- }else {
- System.out.println("json response: " + json.toString());
- result=true;
- }
- pw.println(authorizemessage); //authorize
- pw.flush();
- //read response
- in = new BufferedReader(new InputStreamReader(is));
- json = new JSONObject(in.readLine());
- if(!json.has("result")) {
- System.out.println("no reult");
- result=false;
- }else {
- System.out.println("json response: " + json.toString());
- result=true;
- }
- is.close();
- os.close();
- socket.close();
- } catch (IOException e) {
- System.out.println(e.getMessage());
- System.out.println("Not able to connect to pool");
- System.exit(-2);
- } catch (JSONException e) {
- System.out.println(e.getMessage());
- System.out.println("JSON not good.");
- System.exit(-2);
- }
- return result;
- } //end of connect2Pool
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement