目前我使用下面的代碼與服務器TCP/IP的開放連接
public String connectToserverforincomingmsgs(String phonurl, String phno)
throws IOException {
URL url = new URL(phonurl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setDoInput(true);
// Allow Outputs
con.setDoOutput(true);
con.connect();
BufferedWriter writer = null;
writer = new BufferedWriter(new OutputStreamWriter(
con.getOutputStream(), "UTF-8"));
// give server your all parameters and values (replace param1 with you
// param1 name and value with your one's)
writer.write("sender_no=" + phno);
writer.flush();
String responseString = "";
BufferedReader reader = null;
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
responseString = responseString.concat(line);
}
con.disconnect();
return responseString;
}
互動我怎麼能做出TCP連接.right現在我沒有任何想法。我是新來的android和java以及所以任何關於TCP連接的示例代碼將不勝感激
你想的是什麼協議使用?它是HTTP還是你想實現你自己的? – 2012-03-02 11:39:10
@Demand如果需要,我想使用xmpp – BOBRA 2012-03-02 11:43:45
,您需要使用Socket作爲寫入Vivek,或者您可以搜索庫,實現XMPP。 – 2012-03-02 11:48:35