【发布时间】:2014-08-17 06:52:57
【问题描述】:
我想在我的 android 应用程序中实现一个功能来打开/关闭我的 av 接收器。 因此,我创建了一个套接字并通过 Telnet 向接收器发送命令,但没有任何反应。 Socket创建成功!
我的 AV 接收器是 Denon x-2000,根据官方协议,我必须发送 PWSTANDBY 命令。
public void turnOff(View v){
Runnable r = new Runnable() {
@Override
public void run() {
Socket s = null;
PrintWriter out = null;
BufferedReader in= null;
try{
InetAddress ia = InetAddress.getByName("192.168.100.228");
s= new Socket(ia, 23);
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
} catch(IOException e){
}
Log.v("output","send standby");
out.println("PWSTANDBY");
out.flush();
try {
if(in.ready())
Log.v("input", in.readLine());
} catch (IOException e) {
e.printStackTrace();
}
out.close();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
s.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
Thread t = new Thread(r);
t.start();
}
【问题讨论】:
标签: java android sockets telnet