android socket 编程 值得注意的地方

来源:互联网 发布:冷冰网络歌手 编辑:程序博客网 时间:2024/04/29 18:50

从开发web 到学习Android  本以为在sorcket 编程上没有什么区别,但还是出乎意料

第一点:在android中服务器端ip 可以写localhost,或者什么的,android虚拟机上 要访问服务器的话 要写10.0.2.2第二点:在android2.3 版本之后就不能再主线程中 访问网络,一定要单独开一个线程中执行访问网络, 如若不另外开一个线程,就要
 onCreate()方法里面加上StrictMode.ThreadPolicy policy=new StrictMode.ThreadPolicy.Builder().permitAll().build();StrictMode.setThreadPolicy(policy);就可以解决你的问题。另外在类的前面,可能要加上@SuppressLint("NewApi")才行。
 java.lang.ClassNotFoundException: xxxxxxxxxxxx 错误
首先 类必须实现序列化接口
然后类名,包名 必须一样。


0 0