Back to project page ConnectedSpace.
The source code is released under:
Copyright (c) 2015, Shreyas Raman <skraman1999@gmail.com>.
If you think the Android project ConnectedSpace listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package me.shreyasr.connected.android.networking; //from w ww . j a v a 2s .co m import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Intent; import android.os.Handler; import android.os.Looper; import java.io.IOException; import java.net.InetAddress; import java.net.Socket; import me.shreyasr.connected.android.AndroidLauncher; import me.shreyasr.connected.network.NetworkHandler; public class ConnectionThread implements Runnable { private Socket socket; private final InetAddress remote; private final Activity lobbyActivity; private AlertDialog dialog; public ConnectionThread(Activity lobbyActivity, InetAddress remote) { this.lobbyActivity = lobbyActivity; this.remote = remote; } @Override public void run() { try { socket = new Socket(remote, 4243); } catch (IOException e) { e.printStackTrace(); } new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { dialog = new ProgressDialog.Builder(lobbyActivity) .setTitle("Waiting") .setMessage("Waiting for Request Acknowledgement") .setIcon(android.R.drawable.ic_dialog_alert) .show(); } }); int accept = -1; while (accept == -1) { try { accept = socket.getInputStream().read(); } catch (IOException e) { e.printStackTrace(); } } dialog.cancel(); if (accept == 1) new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { AndroidLauncher.network = new NetworkHandler(socket); Intent intent = new Intent(lobbyActivity, AndroidLauncher.class); lobbyActivity.startActivity(intent); } }); } }