Question: Tcp/Ip in Java/Android. Consider the Java Android code snippet below, which is taken from the example in the Android Networking section on TCP/IP connects (echo

 Tcp/Ip in Java/Android. Consider the Java Android code snippet below, which

Tcp/Ip in Java/Android. Consider the Java Android code snippet below, which is taken from the example in the Android Networking section on TCP/IP connects (echo server/client). No errors have been introduced. This code comes from the Android app which is a client to the Echo Server, and is the main Activity. It is in the doInBackground method of the internal class whose declaration is shown below. With Java, the connection with the server is created when the Socket constructor is called. private class EchoRequestTask extends AsyncTask{... protected String doInBackground(String... to Sends) { String ret = ""; for (String aMsg: to Sends) { try if ((sock != null && sock.isClosed()) || sock == null) { sock = new Socket (host, port); os = sock.getOutputStream(); is = sock.getInputStream(); In the code above, consider the statement: sock = new Socket (host, port); Which of the following statements best describe the execution of this Socket constructor in the context of the AsyncTask's doInBackground method? The call to the Socket constructor is best considered an asynchronous method call. It should not block the Async Task's dolnBackground method because that method runs on the Main or UiThread. The call to the Socket constructor is a blocking call. That is, execution does not proceed beyond the call until the corresponding server (in this case the Echo Server) accepts the connection. This blocking operation should occur in the Async Task's doinBackground method because that method runs on the Main or UI Thread The call to the Socket constructor is a blocking call. That is, execution does not proceed beyond the call until the corresponding server (in this case the Echo Server) accepts the connection. This blocking operation should occur in the Async Task's doinBackground method because doinBackground runs on a thread that is separate/different from the Main or UlThread. The call to the Socket constructor is NOT a blocking call. That is, execution immediately proceeds beyond the call since it does not wait until the corresponding server (in this case the Echo Server) accepts the connection

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!