我正在使用Android客户端连接到Python服务器。这是我的Android客户端代码,它使用相同的无线IP地址通过移动三星迷你galaxy通过Open socket连接到服务器:
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 socket");
} catch (SocketException e) {
e.printStackTrace();
}
catch(Exception e){
System.out.println("Error");
}
}
现在的问题是我可以连接并且我有按钮发送appendtext的动作事件,但是它没有让我使用手机发送。我的代码有什么问题?