0

I am trying to receive port based SMS with the below piece of code.

         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);                  
        }

Will it wait in the line of serverSocket.accept(); until it gets the port based SMS,Is this correct behaviour or I am making any issue which hangs at that place.I am not able to move beyond it.

I am not able to test fully,I am not having option of testing it here,sending the port message.

Did anyone came across this issue.Any Info regarding this will be useful.

Rakesh
  • 14,997
  • 13
  • 42
  • 62

1 Answers1

0

I think you could try adding the while statement
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);
} }

and for as long as it's true, it will wait for the client to send a message. It's been a while since i last did one of these Working with Datagrams

Zuko
  • 2,764
  • 30
  • 30