你好,游客 登录 注册 搜索
背景:
阅读新闻

Socket在Android中的应用

[日期:2012-04-04] 来源:Linux社区  作者:郝浩 [字体:大 中 小]

XML文件布局:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3. android:orientation="vertical" android:layout_width="fill_parent"  
  4. android:layout_height="fill_parent">  
  5. <TextView android:id="@+id/TextView" android:singleLine="false"  
  6.   android:layout_width="fill_parent"  
  7.   android:layout_height="wrap_content" />  
  8. <EditText android:hint="content" android:id="@+id/EditText01"  
  9.   android:layout_width="fill_parent"  
  10.   android:layout_height="wrap_content">  
  11. </EditText>  
  12. <Button android:text="login" android:id="@+id/Button01"  
  13.   android:layout_width="fill_parent"  
  14.   android:layout_height="wrap_content">  
  15. </Button>  
  16. <Button android:text="send" android:id="@+id/Button02"  
  17.   android:layout_width="fill_parent"  
  18.   android:layout_height="wrap_content">  
  19. </Button>  
  20. </LinearLayout>  

先启动服务器端,再运行客户端程序。

注意:(一)即使服务器端和客户端在一台机器上运行,也不能使用ip地址:127.0.0.1,否则,程序会出现拒绝连接的错误。

(二)客户端和服务器端最好不要建在一个工程下,最好是分别建立工程,然后启动服务器端和客户端,否则会报Error: ShouldNotReachHere()错误。这是因为Android程序不是已main方法为程序的入口。

运行效果:

linux
相关资讯       Android开发入门 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款