-
Notifications
You must be signed in to change notification settings - Fork 6
/
RPCThread.java
76 lines (71 loc) · 2.08 KB
/
RPCThread.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Curecoin 2.0.0a Source Code
* Copyright (c) 2015 Curecoin Developers
* Distributed under MIT License
* Requires Apache Commons Library
* Supports Java 1.7+
*/
import java.io.*;
import java.net.*;
/**
* RPCThreads are server threads, allowing client communication with the daemon.
*/
public class RPCThread extends Thread
{
private Socket socket;
public String request;
public String response;
/**
* RPC Threads require a socket to function.
*
* @param socket Socket
*/
public RPCThread(Socket socket)
{
this.socket = socket;
}
/**
* Manages the server<->client communication.
*/
public void run()
{
try
{
request = null;
response = null;
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
String input = "";
out.println("Curecoin 2.0.0a5 daemon RPC");
while ((input = in.readLine()) != null)
{
if (input.equalsIgnoreCase("HELP"))
{
out.println("Commands: ");
out.println("send <amount> <destination>");
out.println("getinfo");
out.println("getbalance <address>");
out.println("submittx <rawtx>");
out.println("submitcert <cert>");
out.println("gethistory <address>");
out.println("");
}
else
{
request = input;
while (response == null)
{
Thread.sleep(25);
}
out.println(response + "\n</>");
request = null;
response = null;
}
}
} catch (Exception e)
{
System.out.println("An RPC client has disconnected.");
//e.printStackTrace();
}
}
}