hi, i found a simple example of a multithread client and multithread
server here : http://www.ase.md/~aursu/ClientServerThreads.html (in
the end of the page). there's a simple multithread server that aceepts
multiple connections, and a multithread client that read the input
from the console and has a thread to write the output on the console.
 So i tried to use this on my Android application, i took the server
as it was and created an Activity with a textview, an edittext and a
button. my idea was to change the input from the console to the
edittext with something like

outputstream.write(EditText.getText().tostring());
where outputstream is my stream variable of the socket and Edittext is
my edittext variable in the activity

and to change the output to my textview in the thread of the client
like

textview.append(responseLine+"\n");

where textview is my textview object in my activity and responsilne is
my string line from the socket, obtained with
responseLine = inputstream.readLine();

my activity creates the socket in the oncreate method, creates a
buffered reader object and a buffered writer object and initiaize them
like this:
BufferedWriter writer = null;
writer = new BufferedWriter(new OutputStreamWriter(socket
.getOutputStream()));
same for the inputstream;

 the activity has an onclick method that calls this method to read
from the edittext when i click the button

private void showtext ( editext et, bufferedwriter writer) {
String input = et.gettext().tostring();
writer.write(input, 0, input.length());
}

this kinda works, the problems come with appending text to the
textview. I created a private class like this

private class Chatthread extends thread {
bufferedreader reader;
textview tv;
private Chatthread ( textview tv, buferedreader reader){
this.tv=tv;
this.reader=reader;}
pubic void run(){
String output ;

while ((output = reader.readLine();) != null) {
                tv.append(output+"\n");
            }

}
}
my activity calls the thread after making the connection (the socket)
and pass to it the textview object and the socket object
new Thread(new Chatthread(textview, reader)).start();

and it doesn't work >_< the application stops. it's a null pointer?
should i create something like a subactivity for the textview? i'm
quite a newbie here so please help.
i didn't post the whole code and i hope the situation is clear, if not
i'll post it.

thanks for your help in advance

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to