我正在尝试使用以下代码接收基于端口的SMS。
serverSocket = new ServerSocket(SERVERPORT);
Socket client = serverSocket.accept();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
line = null;
while ((line = in.readLine()) != null) {
Log.d("ServerActivity", line);
System.out.println("Reading Line is>>>>>>>>>>>>>"+line);
break;
}
} catch (Exception e) {
System.out.println("Exception While Reading SMS>>>>>>>>>>"+e);
}
它会在 serverSocket.accept(); 的行中等待,直到它获得基于端口的SMS,这是正确的行为还是我在那个地方挂起任何问题。我不是能够超越它。
我无法完全测试,我没有选择在此测试它,发送端口消息。
有没有人遇到过这个问题。有关此问题的任何信息都会有用。
答案 0 :(得分:0)
我认为您可以尝试添加while语句
serverSocket = new ServerSocket(SERVERPORT);
while(true){
Socket client = serverSocket.accept();
try {
BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
line = null;
while ((line = in.readLine()) != null) {
Log.d("ServerActivity", line);
System.out.println("Reading Line is>>>>>>>>>>>>>"+line);
break;
}
} catch (Exception e) {
System.out.println("Exception While Reading SMS>>>>>>>>>>"+e);
}
}
只要它是真的,它将等待客户端发送消息。自从我上次做了其中一个Working with Datagrams