package com.oyp.shutdown;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.Toast;
public class ControlActivity extends Activity implements OnClickListener {
private Button btn_shutdown, btn_restart, btn_cancel, btn_close;
private Socket clientSocket;// 客户端socket
private DataOutputStream dataOutput = null;// 客户端发送数据
private DataInputStream dataInput = null;// 客户端接收数据
private String connIP = "";
private ConnThread connThread = null;
private Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
Toast.makeText(ControlActivity.this, (String) msg.obj,
Toast.LENGTH_SHORT).show();
break;
default:
break;
}
super.handleMessage(msg);
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_LEFT_ICON);
setContentView(R.layout.layout_control);
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,
R.drawable.acticon);
btn_shutdown = (Button) findViewById(R.id.btnShutdown);
btn_restart = (Button) findViewById(R.id.btnReboot);
btn_cancel = (Button) findViewById(R.id.btnCancel);
btn_close = (Button) findViewById(R.id.btnClose);
Intent intent = getIntent();
connIP = intent.getStringExtra("ip");
btn_shutdown.setOnClickListener(this);
btn_restart.setOnClickListener(this);
btn_cancel.setOnClickListener(this);
btn_close.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// 连接服务器
switch (v.getId()) {
case R.id.btnShutdown:
final String shutdown = "shutdown";
if (connThread != null) {
connThread.interrupt();
}
connThread = new ConnThread(connIP, 30000, shutdown);
connThread.start();
break;
case R.id.btnReboot:
final String reboot = "reboot";
if (connThread != null) {
connThread.interrupt();
}
connThread = new ConnThread(connIP, 30000, reboot);
connThread.start();
break;
case R.id.btnCancel:
final String cancel = "cancel";
if (connThread != null) {
connThread.interrupt();
}
connThread = new ConnThread(connIP, 30000, cancel);
connThread.start();
break;
case R.id.btnClose:
finish();
break;
default:
break;
}
}
class ConnThread extends Thread {
private String ip;
private int port;
private String content;
public ConnThread(String ip, int port, String content) {
this.ip = ip;
this.port = port;
this.content = content;
}
@Override
public void run() {
try {
clientSocket = new Socket(ip, port);
while (true) {
dataOutput = new DataOutputStream(
clientSocket.getOutputStream());
dataInput = new DataInputStream(
clientSocket.getInputStream());
String msg = "";
if ((dataOutput != null) && (!content.equals(""))) {
dataOutput.writeUTF(content);
}
msg = dataInput.readUTF();
if (msg != null && !"".equals(msg)) {
Message message = new Message();
message.what = 1;
message.obj = msg;
handler.sendMessage(message);
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (dataOutput != null) {
dataOutput.close();
}
if (dataInput != null) {
dataInput.close();
}
if (clientSocket != null) {
clientSocket = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
super.run();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(一)PC服务器端 (地址:http://blog.csdn.net/ouyang_peng/article/details/47004617) 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(二)Android客户端功能展示 (地址:http://blog.csdn.net/ouyang_peng/article/details/47005739) 我的Android进阶之旅------>Android实现用Android手机控制PC端的关机和重启的功能(三)Android客户端功能实现 (地址:http://blog.csdn.net/ouyang_peng/article/details/47007509)
资源推荐
资源详情
资源评论
收起资源包目录
ShutDownClient&Server.rar (68个子文件)
ShutDownServer
bin
com
oyp
shutdown
ShutDownServer.class 3KB
.settings
org.eclipse.jdt.core.prefs 598B
src
com
oyp
shutdown
ShutDownServer.java 2KB
.project 390B
.classpath 301B
ShutDownClient
bin
classes.dex 12KB
res
crunch
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 6KB
drawable
btn_close_pressed.png 2KB
btn_normal.png 672B
btn_close_focused.png 2KB
btn_close_normal.png 672B
acticon.png 7KB
btn_pressed.png 2KB
btn_focused.png 2KB
drawable-mdpi
icon.png 2KB
jarlist.cache 120B
dexedLibs
annotations-6955873263f1351210e289165221bda5.jar 943B
classes
com
oyp
shutdown
BuildConfig.class 341B
ControlActivity$ConnThread.class 3KB
R$layout.class 472B
R$id.class 682B
R$drawable.class 729B
MyWifiManager.class 2KB
R$attr.class 334B
ControlActivity$1.class 1017B
ScanActivity.class 2KB
R.class 563B
ControlActivity.class 4KB
ScanActivity$1.class 2KB
R$string.class 753B
ScanActivity$ScanIPThread.class 2KB
ReScanActivity.class 2KB
R$style.class 432B
resources.ap_ 35KB
ex_AcontrolPC_A.apk 44KB
AndroidManifest.xml 1KB
ShutDownClient.apk 43KB
res
drawable-ldpi
icon.png 2KB
drawable-hdpi
icon.png 8KB
drawable-xhdpi
drawable
btn_close_pressed.png 2KB
btn_normal.png 672B
btn_close_focused.png 2KB
btn_close_selector.xml 456B
btn_close_normal.png 672B
acticon.png 7KB
btn_pressed.png 2KB
btn_selector.xml 432B
btn_focused.png 2KB
values
strings.xml 708B
styles.xml 1KB
ids.xml 484B
drawable-mdpi
icon.png 3KB
layout
layout_rescan.xml 513B
layout_scanip.xml 1KB
layout_control.xml 1KB
assets
gen
com
oyp
shutdown
BuildConfig.java 158B
R.java 3KB
proguard.cfg 1KB
.settings
org.eclipse.jdt.core.prefs 177B
src
com
oyp
shutdown
ScanActivity.java 3KB
ControlActivity.java 4KB
MyWifiManager.java 1KB
ReScanActivity.java 1KB
.project 850B
.classpath 475B
project.properties 563B
AndroidManifest.xml 1KB
共 68 条
- 1
资源评论
- weichen_Hi2016-04-09非常感谢,刚好有用
- m0_375790812017-11-12谢谢谢谢谢
字节卷动
- 粉丝: 4w+
- 资源: 52
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 计算机专业毕业设计,基于Vue + ECharts的数据可视化系统的设计与实现
- Word1_20240424_000136.docx
- 图片网站图片爬虫Python代码
- 同城佳俪
- MATLAB实现LSTM神经网络预测数值(调用MATLAB自带lstm工具箱)
- %E5%B0%8F%E5%B0%8F%E5%A3%B0%E6%98%8E 3.zip
- jdk和idea安装使用教程
- python绘图时渐变的处理-以一个扇形图的渐变为例.html
- 基于STC15F104W的学习型无线遥控解码原理图+程序+说明和433程序+说明
- RIME-BP霜冰优化BP神经网络多特征分类预测(Matlab实现完整源码和数据)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功