Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 33rd International Conference Dexa 2022 Vienna Austria August 22 24 2022 Proceedings Part 1 Lncs 13426

Authors: Christine Strauss ,Alfredo Cuzzocrea ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

3031124227, 978-3031124228

More Books

Students also viewed these Databases questions

Question

3-2 What is the impact of information systems on organizations?

Answered: 1 week ago