I'm doing a simple irc client (just to test sockets). I've got a textView in the main layout where to write server responses, and a socket to connect and send commands to the server.
The problem is the textView is not writting anything but if i debug it, it does!
My code is like this (sorry for the mess, it's just a proof of concept):
Using java Syntax Highlighting
- private TextView text;
- private PrintWriter output;
- private BufferedReader input;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- text = (TextView) findViewById(R.id.text);
- try{
- text.setText("Welcome to droidChat \n");
- Socket socket = new Socket(SERVER, PORT);
- input = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- output = new PrintWriter(socket.getOutputStream(), true);
- String reply = sendCommand("PASS NOPASS\n\r");
- reply += sendCommand("NICK " +NICK+"\n\r");
- reply += sendCommand("USER "+NICK+EOF );
- reply += sendCommand ("JOIN #misatofans");
- text.setText(reply);
- } catch(Exception ex){
- ex.printStackTrace();
- text.append(ex.getMessage());
- }
- }
- private String sendCommand(String msg){
- String reply = "";
- try{
- output.println(msg);
- reply = input.readLine();
- }catch (Exception ex){
- text.append(ex.getMessage());
- }
- output.flush();
- return reply;
- }
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
I've read something about handlers and threads but i don't understand how to use it propperly in my case.
What i've figured out, it may be a problem with the refresh of the screen or something similar (maybe i'm wrong) but i don't know how to solve it.
Thanks in advance