java - Desktop server and android client local connection -
i try connect windows desktop java server android client. i'm working cross-platform. desktop server , desktop client working fine same code, desktop server , android client has interesting problem. manifest permissions setted.
desktop java server code
serversocket serversocket = new serversocket(tcp_port); socket link = null; while(true) { link = serversocket.accept(); printwriter output = new printwriter(link.getoutputstream(),true); // flush true bufferedreader input = new bufferedreader(new inputstreamreader(link.getinputstream())); // step 1 password auth string message = input.readline(); // wait password if(message.equals(password)) { output.println("correct"); message = null; message = input.readline(); // wait udp port request if(message.equals("udp")) { output.println(udp_port+""); etc . .
android client code
socket link = null; link = new socket(hostip,tcp_port); printwriter output = new printwriter(link.getoutputstream(),true); // auto flush true bufferedreader input = new bufferedreader(new inputstreamreader(link.getinputstream())); while(true) { // step1 send password wait response output.println(password); string message = input.readline(); // password response if(message.equals("correct")) { output.println("udp"); // request udp message = null; message = input.readline(); udpport = integer.parseint(message); etc . .
my problem same code works fine on java desktop client , java desktop server when try connect java desktop server android client password auth part works fine
output.println(udp_port+""); send data 2 times when looked server side sends empty string firstly , sends value wrong ?
message = null; message = input.readline(); // wait udp port request if(message.equals("udp")) {
it reads empty string , jump if statement if use
message = null; message = input.readline(); // read empty string message = input.readline(); // read data if(message.equals("udp")) { statement works
this expected behavior if try read data before has been received - more occur when receiving remote system, possibility must allow for.
your application must wait until full message has been collected, in case looping on readline() call until non-null message.
Comments
Post a Comment