Есть такой код: (Пишу для игры одной)
package jerke;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HttpsURLConnection;
public class HttpURLConnectionExample {
private final static String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) throws Exception {
HttpURLConnectionExample http = new HttpURLConnectionExample();
init();
mainLoop();
}
private static void mainLoop() throws Exception {
String[] chat = null;
String message = null;
sendMsg("");
while (message != "!stopit"){
String cht = getChat();
cht = cht.replaceAll("<###>", "\n");
chat = cht.trim().split("\n");
String chto = chat[0];
String[] data = chto.substring(10).split("<>"); // 50ml
String logi = data[0].toString();
System.out.println(data[1]);
message = data[1];
TimeUnit.SECONDS.sleep(1);
};
sendMsg("Elite hax0r bot went offline.");
}
static void init() throws Exception {
String cht = getChat();
cht = cht.replaceAll("<###>", "\n");
String[] chat = cht.trim().split("\n");
System.out.println(chat);
}
//------------------------------------
//Далее скорее всего не нужная вам часть
//------------------------------------
// HTTP GET request
private static String getChat() throws Exception {
String url = "https://www.hackingsimulator.com/i133/process_chat.php?cmd=get_chat&u=hax0r&p=1q2w3e4r&channel=home";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
//print result
return response.toString().replace('*', ' ').replace(')', ' ');
}
// HTTP POST request
private static void sendMsg(String msg) throws Exception {
String url = "https://www.hackingsimulator.com/i133/process_chat.php";
URL obj = new URL(url);
HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
//add reuqest header
con.setRequestMethod("POST");
con.setRequestProperty("User-Agent", USER_AGENT);
con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
String urlParameters = "cmd=add_chat&u=hax0r&p=1q2w3e4r&channel=home&msg=" + msg;
// Send post request
con.setDoOutput(true);
DataOutputStream wr = new DataOutputStream(con.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
int responseCode = con.getResponseCode();
System.out.println("\nSending 'POST' request to URL : " + url);
System.out.println("Post parameters : " + urlParameters);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
System.out.println(response.toString());
}
}
Знаю, код - лапша, но почему всё-таки не реагирует while на переменную message?