Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/session.php on line 1007: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)

Strict Standards: Non-static method utf_normalizer::nfc() should not be called statically in /www/htdocs/w006661d/anddev/includes/utf/utf_tools.php on line 1781
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4362: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4364: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4365: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
[phpBB Debug] PHP Notice: in file /includes/functions.php on line 4366: Cannot modify header information - headers already sent by (output started at /includes/utf/utf_tools.php:1781)
anddev.org • View topic - How to pass string from TCP server to main activity?

How to pass string from TCP server to main activity?

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

How to pass string from TCP server to main activity?

Postby madhunandan » Fri Dec 10, 2010 2:59 pm

Hi,

Please help me with passing a string from TCP server to the main activity.

The code for server and main activity is below.

Thank you for any suggestion and time spent on this.

Cheers,
Madhu Nandan

TCPIPServer


public class TCPIPServer extends Activity implements Runnable{

public static final String SERVERIP = "127.0.0.1";
public static final int SERVERPORT = 7777;
//private final Handler mHandler;

//public TCPIPServer(Context context, Handler handler) {
// mHandler = handler;
//}

public void run() {
try {
Log.d("TCP","S: Connecting...");

ServerSocket serverSocket = new ServerSocket(SERVERPORT);
while (true) {

Socket client = serverSocket.accept();
Log.d("TCP","S: Receiving...");

try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
String str = in.readLine();
Log.d("TCP","S: Received: '" + str + "'");
//Pass str to main activity for parsing
} catch(Exception e) {
Log.d("TCP","S: Error", e);
e.printStackTrace();
} finally {
client.close();
Log.d("TCP","S: Done danaadan.");
}

}

} catch (Exception e) {
Log.d("TCP","S: Error", e);
e.printStackTrace();
}
}


}


TCPIPCommn (the main activity)


public class TCPIPCommn extends Activity {

//private TCPIPServer mServer = null;
//mServer = new TCPIPServer(this, mHandler);

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Thread cThread = new Thread(new TCPIPServer());

cThread.start();
}

//private final Handler mHandler = new Handler() {
//Function to extract name and value from the received message
public void extractData(String tempStr) {
code...
code...
}

//Function to display driver messages/images based on individual messages
public void actionOnData(String name, double value) {
code...
code...
}

}
User avatar
madhunandan
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Dec 08, 2010 4:40 pm
Location: Rüsselsheim, Germany

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 11 guests