-2
我使用下面的代码为tcp连接tcp连接来获得IMEI
public String connectToservertocheckuserstatus(String phonurl, String imei)
throws IOException {
URL url = new URL(phonurl);
Socket sock=new Socket("localhost", 123);
sock.connect(url);
//con.setDoInput(true);
// Allow Outputs
//con.setDoOutput(true);
//con.connect();
BufferedWriter writer = null;
writer = new BufferedWriter(new OutputStreamWriter(
sock.getOutputStream(), "UTF-8"));
// give server your all parameters and values (replace param1 with you
// param1 name and value with your one's)
writer.write("imei=" + imei);
writer.flush();
String responseString = "";
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
responseString = responseString.concat(line);
}
sock.close();
return responseString;
}
但我发现了问题。我的conncetion字符串是:
String imeiurl = appConstants.ip + "/tel_dir/imei.php";
但它不工作。你能告诉我它有什么问题吗?
请发布您正面临的问题和logcat错误转储的详细信息。 – 2012-03-02 13:26:19
sock.connect(URL)甚至没有编译。你真正的代码是什么? – EJP 2012-03-03 01:34:07