Java Reference
In-Depth Information
void addLine (String line) {
list.append (line, null);
}
void disconnect() {
if (timer != null) {
timer.cancel();
timer = null;
}
}
boolean transfer (String submit) { // if null, just read
try {
HttpConnection connection = (HttpConnection)
Connector.open
(host + "/?start="+count,
submit != null ? Connector.READ_WRITE :
Connector.READ);
Writer writer = null;
if (submit != null) {
connection.setRequestMethod (HttpConnection.POST);
writer = new OutputStreamWriter
(((StreamConnection)
connection).openOutputStream());
writer.write ("nick="+nick + "\r\n");
writer.write ("text="+submit+"\r\n");
writer.close();
}
Reader reader = new InputStreamReader
(((StreamConnection) connection).openInputStream());
count = Integer.parseInt (readLine (reader));
while (true) {
String s = readLine (reader);
if (s == null || s.length() == 0) break;
addLine (s);
}
reader.close();
connection.close();
return true;
}
catch (Exception e) {
addLine (e.toString());
disconnect();
return false;
}
}
public void commandAction(Command c, Displayable d) {
if (c == write) {
display.setCurrent (text);
}
else {
if (c == submit) {
transfer (text.getString());
text.setString ("");
}
Search WWH ::




Custom Search