小编Ngu*_*Huy的帖子

在Android中连接2个仿真器实例

我想在2 Emulator中创建一个Server和一个Client来写入和读取数据.我为Server编写代码:

public class ServerActivity extends Activity {
    /** Called when the activity is first created. */
 private ServerSocket serverSocket = null;
 private TextView tv;
 public static final int SERVERPORT = 4444;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv= (TextView) findViewById(R.id.myTextView);
        try {
   Connect();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   tv.setText("Not connected");
   e.printStackTrace();
  }
    }

    public void Connect() throws IOException
    {
     serverSocket = new ServerSocket();
     serverSocket.bind(new InetSocketAddress("10.0.2.15", 4444));
     while(true)
     {
      Socket socket = serverSocket.accept(); …
Run Code Online (Sandbox Code Playgroud)

android

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1