Note that there are some explanatory texts on larger screens.

plurals
  1. POCommunicate between android Application and java
    primarykey
    data
    text
    <p>Every body i am new in program world , I am getting a issue,My Request is related to Communication between Android tablet to Desktop PC using JAVA Code.</p> <pre><code> import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class HelloWorldServlet extends HttpServlet { private static final long serialVersionUID = 1L; public HelloWorldServlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("Hello Android !!!!"); } } </code></pre> <p>above code is my servlet code which is running in my local system server (Tomcat 6.0 ) here i am sending message through println and i want to reveive same message in my Android app which is running in another system. Now i am going to post my android code which is running on another system.</p> <pre><code> import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class HttpGetServletActivity3 extends Activity implements OnClickListener { Button button; TextView outputText; public static final String URL = "http://192.168.0.2:9999/HttpGetServlet/HelloWorldServlet"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); findViewsById(); button.setOnClickListener(this); } private void findViewsById() { button = (Button) findViewById(R.id.button); outputText = (TextView) findViewById(R.id.outputTxt); } public void onClick(View view) { GetXMLTask task = new GetXMLTask(); task.execute(new String[] { URL }); } private class GetXMLTask extends AsyncTask&lt;String, Void, String&gt; { @Override protected String doInBackground(String... urls) { String output = null; for (String url : urls) { output = getOutputFromUrl(url); } return output; } private String getOutputFromUrl(String url) { StringBuffer output = new StringBuffer(""); try { InputStream stream = getHttpConnection(url); BufferedReader buffer = new BufferedReader( new InputStreamReader(stream)); String s = ""; while ((s = buffer.readLine()) != null) output.append(s); } catch (IOException e1) { e1.printStackTrace(); } return output.toString(); } // Makes HttpURLConnection and returns InputStream private InputStream getHttpConnection(String urlString) throws IOException { InputStream stream = null; URL url = new URL(urlString); URLConnection connection = url.openConnection(); try { HttpURLConnection httpConnection = (HttpURLConnection) connection; httpConnection.setRequestMethod("GET"); httpConnection.connect(); if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { stream = httpConnection.getInputStream(); } } catch (Exception ex) { ex.printStackTrace(); } return stream; } @Override protected void onPostExecute(String output) { outputText.setText(output); } }} </code></pre> <p>Here 192.68.0.2 is ip address of system where servlet code is running in my local system (Tomcat6.0 server which has port no 9999) .But it is not working for me.Both the system are in same wifi network Any help is really very appreciated. Thanks in advance to all</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload