0
我用從服務器到我的Android應用程序通信問題,basiclly通信是這樣的:爲什麼不讀第二行?
1. send x and y
2. get the list of coordinates from server
3. send "ok"
4. receive titles string
一切進展順利,直到最後一行,我知道這是正常發送,因爲它通過telnet工作,但我的Android應用程序沒有收到任何東西。下面是用於發送和接收客戶端代碼:
clientSocket = new Socket("10.0.2.2", 1234);
Log.d("LatitudeE6", ""+point.getLatitudeE6());
Log.d("LongitudeE6", ""+point.getLongitudeE6());
os = new PrintStream(clientSocket.getOutputStream());
is = new DataInputStream(clientSocket.getInputStream());
sentenceX = ""+point.getLatitudeE6();
sentenceY = ""+point.getLongitudeE6();
os.println(sentenceX + " "+ sentenceY+'\n');
String thing =is.readLine();
String [] holder = thing.split("\\s+");
System.out.println("thing printed: " +thing);
os.println("ok\n");
String test = is.readLine();
System.out.println("tester: " +test); // this doesn' work
服務器:
try{
in = new DataInputStream(clientSocket.getInputStream());
os = new PrintStream(clientSocket.getOutputStream());
ms.connector();
while(true){
line = in.readLine();
if(line.startsWith("51789181 19426953")==true){
// these are the coordinates, if the client sends them, it will receive the list of other coordinates
os.println(ms.lister().toString().replace('[', ' ').replace(']', ' ').trim().replace(',', ' ') +""+'\n');
os.flush();
}else if (line.equals("ok")==true) {
os.flush();
os.println(ms.topicDesc().toString().replace('[', ' ').replace(']', ' ').trim().replace(',', ' ') +""+'\n');
}
}
catch(IOException e){
e.printStackTrace();
}
您發送後確定換行,並刷新插座,在服務器端? –
我剛剛加入「\ n」後「確定」,並刷新插座,但它不會改變任何事情。 – iie
對不起,我miswrote我的評論之前 - 在另一邊的標題字符串後,你發送一個換行符?請顯示服務器代碼。 –