1 package org.pileus.spades;
3 import java.io.BufferedReader;
4 import java.io.PrintWriter;
6 import android.util.Log;
11 private String server = null;
12 private String nickname = null;
13 private String channel = null;
14 private String username = null;
15 private String hostname = null;
17 private BufferedReader input = null;
18 private PrintWriter output = null;
21 public boolean running = true;
24 private void process(Message msg)
26 if (msg.cmd.equals("001") && msg.msg.matches("Welcome.*")) {
27 putline("JOIN " + channel);
28 putline("TOPIC " + channel);
30 if (msg.cmd.equals("PING")) {
31 putline("PING " + msg.msg);
35 private String getline()
38 String line = input.readLine();
39 Log.d("Spades", "> " + line);
41 } catch (Exception e) {
42 Log.d("Spades", "Error reading line", e);
48 private void putline(String line)
51 Log.d("Spades", "< " + line);
54 } catch (Exception e) {
55 Log.d("Spades", "Error writing line", e);
61 public Client(String server, String nickname, String channel,
62 String username, String hostname)
65 this.nickname = nickname;
66 this.channel = channel;
67 this.username = username;
68 this.hostname = hostname;
69 Log.d("Spades", "Client create");
72 public Client(String server, String nickname, String channel)
74 this(server, nickname, channel, "user", "localhost");
75 Log.d("Spades", "Client create");
78 public void connect(BufferedReader input, PrintWriter output)
82 Log.d("Spades", "Client connect");
83 putline("USER "+username+" "+hostname+" "+server+" :"+nickname);
84 putline("NICK "+nickname);
87 public void send(String txt)
94 String line = getline();
95 Message msg = new Message(line);
98 } catch (Exception e) {
99 Log.d("Spades", "Error in recv", e);
100 this.running = false;