我是在android操作系統開發新手。我嘗試開發我的android操作系統的telnet客戶端。 現在,我只嘗試連接telnet服務器,並接收登錄消息。Android telnet客戶端問題
但是,當我啓動套接字連接telnet服務器我收到奇怪的符號??????!????
而不是來自telnet服務器的登錄消息。
public class MainActivity extends Activity {
protected static final int TCP_SERVER_PORT = 23;
protected String inMsg, str;
static Editable sentence;
static String modifedSentence;
BufferedReader inFromUser;
Socket clientSocket = null;
DataOutputStream outToServer=null;
BufferedReader inFromServer=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button startButton = (Button)findViewById(R.id.startButton);
final TextView textView = (TextView)findViewById(R.id.textView);
startButton.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
new Thread(new Runnable() {
@Override
public void run() {
//Create socket
try {
clientSocket = new Socket("192.168.1.1",23);
//Create out stream for ClientSocket
outToServer = new DataOutputStream(clientSocket.getOutputStream());
//Create ib stream for ClientSocket
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
//Receive login message from telnet server
modifedSentence = inFromServer.readLine();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//Update UI activity with login message
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
textView.setText(modifedSentence);
}
});
}
}).start();
}
});
}
protected void onDestroy()
{
try {
clientSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
你能打印產生奇怪符號的字節值並告訴我們它們是什麼嗎? – 2013-03-01 18:39:48
考慮如果[這個問題](http://stackoverflow.com/questions/10413963/telnet-iac-command-answering/10418479#10418479)揭示了你的問題。 – 2013-03-01 18:41:08
謝謝,你是對的。 telnet不是一個簡單的tcp連接 – 2013-03-29 12:03:45