android基于socket的局域网内服务器与客户端加密通信( 六 )


67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.view.View;
import android.widget.TextView;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import butterknife.BindView;
import butterknife.OnClick;
/**
* 服务器界面
*/
public class Function_Socket_Server extends BaseEventActivity {
@BindView(R.id.tv_localAddress)
TextView tv_localAddress;
@BindView(R.id.tv_receivedContent)
TextView tv_receivedContent;
@BindView(R.id.tv_decryptContent)
TextView tv_decryptContent;
private LocalService localService;//用于启动监听的服务
private ServiceConnection sc;//服务连接
@Override
protected void init() {
tv_localAddress.setText(ToolUtil.getHostIP());
sc = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
LocalService.LocalBinder localBinder = (LocalService.LocalBinder) service;
localService = localBinder.getService();
localService.startWaitDataThread();
ToastUtil.showToast(Function_Socket_Server.this, "监听已启动");
}
@Override
public void onServiceDisconnected(ComponentName name) {
}
};
connection();
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void getData(String data) {
tv_receivedContent.setText(data);
tv_decryptContent.setText(AESUtil.decrypt(ConstantUtil.password, data));
}
/**
* 绑定service
*/

推荐阅读