我刚刚编写了一个连接到wifi的应用程序,如下所示:
wifi.setWifiEnabled(false);
wifi.setWifiEnabled(true);
int res = wifi.addNetwork(wificonfigurationA);
boolean b = false;
b = wifi.enableNetwork(res, true);
Log.d("WifiPreference", "enableNetwork returned " + b);
Socket socket = new Socket(serverAddr, 3000);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())), true);
out.println("Hey Server!");
这会导致01-02 00:03:36.882: E/ClientActivity(1550): java.net.ConnectException: /10.10.2.200:3000 - Network is unreachable
错误。请帮忙
答案 0 :(得分:0)
使用connectionManagaer对象执行此操作,并始终在单独的线程中执行此类网络操作。