]> Pileus Git - ~andy/spades/blob - src/org/pileus/spades/Main.java
5424e5d559dcc0a512257b6ba3b923ce6a48dabe
[~andy/spades] / src / org / pileus / spades / Main.java
1 package org.pileus.spades;
2
3 import java.io.*;
4 import java.net.*;
5
6 import android.app.Activity;
7 import android.os.Bundle;
8 import android.util.Log;
9 import android.widget.TextView;
10
11 public class Main extends Activity
12 {
13         /* Configuration */
14         private String server   = "irc.freenode.net";
15         private String nickname = "andydroid";
16         private String channel  = "#rhnoise";
17         private int    port     = 6667;
18
19         /* Private data */
20         private Socket socket = null;
21         private Client client = null;
22
23         /* Public Methods */
24         @Override
25         public void onCreate(Bundle savedInstanceState)
26         {
27                 super.onCreate(savedInstanceState);
28                 setContentView(R.layout.main);
29
30                 try {
31                         this.socket = new Socket(server, port);
32                         this.client = new Client(server, nickname, channel);
33                         Log.d("Spades", "Socket and client created");
34                 } catch(Exception e) {
35                         Log.d("Spades", "Failed to create socket: " + e);
36                         return;
37                 }
38
39                 try {
40                         BufferedReader input  = new BufferedReader(new InputStreamReader(socket.getInputStream()));
41                         PrintWriter    output = new PrintWriter(socket.getOutputStream());
42                         this.client.connect(input, output);
43                         Log.d("Spades", "Client connected");
44                 } catch (Exception e) {
45                         Log.d("Spades", "Failed to create readers writers: " + e);
46                         return;
47                 }
48
49                 TextView text = (TextView)findViewById(R.id.textview);
50                 while (client.running) {
51                         Message msg = client.recv();
52                         if (msg == null)
53                                 continue;
54                 }
55         }
56 }