connect3('123123', '192.168.0.122', 80);
function connect3(str, ip, port) {
if (plus.os.name == "Android") {
var Socket = plus.android.importClass("java.net.Socket");
var PrintWriter = plus.android.importClass("java.io.PrintWriter");
var BufferedWriter = plus.android.importClass("java.io.BufferedWriter");
var OutputStreamWriter = plus.android.importClass("java.io.OutputStreamWriter");
var BufferedReader = plus.android.importClass("java.io.BufferedReader");
var InputStreamReader = plus.android.importClass("java.io.InputStreamReader");
复制代码- //测试改良 var StrictMode = plus.android.importClass("android.os.StrictMode"); var Build = plus.android.importClass("android.os.Build"); if (Build.VERSION.SDK_INT > 9) { var policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } var socket = new Socket(ip, port); var outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()); var bufferWriter = new BufferedWriter(outputStreamWriter); var out = new PrintWriter(bufferWriter, true); out.println(str); var inputStreamReader = new InputStreamReader(socket.getInputStream()); var br = new BufferedReader(inputStreamReader); var msg = br.readLine(); //while(true) { if (msg != null) { console.log(msg); } //msg = br.readLine(); } } //console.log(mac); alert("Done");
复制代码
|
|