Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We have a java server and a android client, we can only message one at a time. W

ID: 3871811 • Letter: W

Question

We have a java server and a android client, we can only message one at a time. When we try to send a continous flow of messages, using a while loop or a for loop, it breaks down.

How can we fix our code to recieve multiple messages continuously? (out of memory error)

We need this to work with andriod compatibility and the the Android Developer Studio. Needs to be a android developer studio java file!!

Please advise.

Thank you

ackage com.example.paul.trial4; import android. support.v7.app.AppCopatActivity; import android.os.Bundle; import android.util.Log; import android.widget.EditText; import java.io. Bufferedwriter; import java.io.Dataoutputstream; import java.io.IOException; import java.io. OutputstreamWriter; import java.io.PrintWriter; import java.net.Socket; import java.util.Scanner; public class MainActivity extends AppCompatActivity f private EditText text; DataOutputstream dout; Socket s=null; Override protected void onCreate (Bundle savedInstanceState) super.onCreate (savedInstanceState); setcontentview (R. layout.activity main); text = (EditText) findViewById(R.ia.editText ) ; final String ip"192.168.0.31"; final int port 3331; new Thread)[ verride ublic void un t try text.setText("connecting"); s=new Socket (ip , port ) ; dout- new DataoutputStream(s.getoutputstream )); dout.writeUTF("hey") dout.flush ) dout.close ) s.close ) )catch (IOException e) e.printStackTrace ) text.setText ("couldnt connect") ).start (0

Explanation / Answer

The fix to your code is given below:

1. As you are sending the messages using while loop and for loop you need to check the loops whether you have done it correct or not and also

2. Please increase the timeout of the server because you are sending multiple messages at a time.

3. Third thing is please check the server port also or change the port number and try again it will work definetly.

4. As you asked for the advice all the neccessary adives are given inorder to working of the code.

Hope This Helps, if you have any doubts Please comment i will get back to you, thank you and please thumbs up

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote