标签:android style http io color ar os java sp
============问题描述============
public class MainActivity extends Activity {
private static final String LOG_TAG = "IP Test";
private EditText chattxt;
private TextView chattxt2;
private Button chatok;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findviews();
setonclick();
chattxt2.setText(getLocalIpAddressV4());
}
public void findviews() {
// chattxt = (EditText) this.findViewById(R.id.chattxt);
chattxt2 = (TextView) this.findViewById(R.id.chattxt2);
chatok = (Button) this.findViewById(R.id.chatOk);
}
private void setonclick() {
chatok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
connecttoserver("I‘m a client!");
// connecttoserver(chattxt.getText().toString());
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
public void connecttoserver(String socketData) throws UnknownHostException,
IOException {
Socket socket = RequestSocket("10.13.33.136", 5000);// 程序一打开执行到这里就停止运行了,不知道为什么?手机连的是wifi,地址是10.24.28.139,网关10.24.16.1,电脑ip是10.13.33.136,网关是10.13.33.1,所以这里感觉应该是是不在一个导致的,但是为啥手机能打开我本机的网站,地址为:http://10.13.33.136:8080/phnt ps:网络学的不好~T_T
// Socket socket = new Socket("10.13.33.136", 5000);
// SendMsg(socket, socketData);
// String txt = ReceiveMsg(socket);
// this.chattxt2.setText(txt);
}
private Socket RequestSocket(String host, int port)
throws UnknownHostException, IOException {
Socket socket = new Socket(host, port);
return socket;
}
private void SendMsg(Socket socket, String msg) throws IOException {
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
socket.getOutputStream()));
writer.write(msg.replace("\n", " ") + "\n");
writer.flush();
}
private String ReceiveMsg(Socket socket) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(
socket.getInputStream()));
String txt = reader.readLine();
return txt;
}
============解决方案1============
============解决方案2============
============解决方案3============
============解决方案4============
============解决方案5============
标签:android style http io color ar os java sp
原文地址:http://www.cnblogs.com/llj1985522/p/4083238.html