Android socket can't send sentence
I'm using an Android client to connect to a Python server. here is my Android client code, which connects via mobile Samsung mini galaxy to the sever via Open socket using same wireless IP address:
public void appendText(View view){
Text.append( "\n In chat ");
try{
// while (true)
//{
sentence=inputfld.getText().toString();
String sentence1=("hohohoh");
Text.append( "\n DataStream creating");
outToServer.writeBytes(sentence);
outToServer.writeBytes(sentence1);
modifiedSentence = inFromServer.readLine();
Text.append(modifiedSentence);
inputfld.setText(null);
}
}
catch(Exception modifiedsentence){
Text.append("Exception");
}
}
public void connect(View view){
try {
String cmd=("My current location is: " );
clientSocket= new Socket("192.168.1.2",54628);
Text.append( "\n created a socket");
outToServer = new DataOutputStream(clientSocket.getOutputStream());
Text.append( "\n created a datastream");
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
Text.append( "\n created a bufferReader");
Text.append( "\n created a sock开发者_开发技巧et");
} catch (SocketException e) {
e.printStackTrace();
}
catch(Exception e){
System.out.println("Error");
}
}
The problem now is that I can connect and I have button to send on action event for appendtext, but it didn't let me send using the mobile. What is wrong in my code?
精彩评论