2012-11-20 118 views
0

我在應用程序 -建立的ServerSocket連接

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(); 
    ) 

爲什麼會收到日誌輸出Log.i("test", "before info ServerSocket");但不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************", ""); 

爲何不new ServerSocket(8050)之後執行使用此代碼?

回答

1

上的Galaxy Nexus的Android 4.1.2代碼創建和綁定插座沒有問題。你的清單中是否有使用權限android:name =「android.permission.INTERNET」?否則,只需預計堆棧跟蹤以及aaa即可。