rainbow
rainbow

Reputation: 43

Establishing ServerSocket connection

I used this code in my application-

 public class BorderCastList extends Activity {
    private VideoView video;
    private ServerSocket server;
    private MediaController media;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //  Settings window for translucent state
    //   this.getWindow().setFormat(PixelFormat.TRANSLUCENT);
    this.setContentView(R.layout.video);
                   new Thread(new Runnable() {

    @Override
    public void run() {
    try {
    Log.i("test", "before info ServerSocket");
    server = new ServerSocket(8050)
    Log.i("test", "after info ServerSocket");
    Log.i("ip:" + server.getLocalSocketAddress() + "----port: "
    + server.getLocalPort(), "");
    Log.i("service ip: " + server.getInetAddress(), "");
    Log.i("Server build success************", "");
    //   Socket socket = server.accept();

    } catch (Exception e) {
    Log.i("aaa", "bbbb");
    e.printStackTrace();
    }
    }
    }).start();
    )

Why am I getting the log output Log.i("test", "before info ServerSocket"); but not Log.i("test", "after info ServerSocket");

 Log.i("ip:" + server.getLocalSocketAddress() + "----port: "+ server.getLocalPort(), "");
 Log.i("server ip: " + server.getInetAddress(), "");
 Log.i("Server build success************", "");

Why does it not execute after new ServerSocket(8050)?

Upvotes: 0

Views: 229

Answers (1)

Audrius Meškauskas
Audrius Meškauskas

Reputation: 21748

On Galaxy Nexus Android 4.1.2 your code creates and binds the socket without problems. Do you have uses-permission android:name="android.permission.INTERNET" in your manifest? Otherwise just expect the stack trace and also bbbb about the aaa.

Upvotes: 1

Related Questions