Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started