代码

	public class OnClickListenerImpl1 implements OnClickListener
	{
		public void onClick(View v)
		{
			if(v == dl)
			{//按下登录按钮
				String editusername =username.getText().toString();
				String editpassword = password.getText().toString();
				if(editusername.trim().equals(""))
				{//当用户名为空时 
					Toast.makeText(SKA3000.this, "请您输入用户名", Toast.LENGTH_SHORT).show();
					return;
				}
				
			if(editpassword.trim().equals(""))
			{//当密码为空时
				Toast.makeText(SKA3000.this, "请您输入密码!", Toast.LENGTH_SHORT).show();
				return;
			}
			//myDialog = ProgressDialog.show(SKA3000.this, "进度", "正在加载...",true);
		
		//final ProgressDialog proDia =ProgressDialog.show(SKA3000.this,
		//"搜索服务器", //对话框显示标题
		//"请耐心等待");//对话框显示文字
		new Thread()
		{  //将耗时的动作放到线程中
			public void run()
			{//重写的run方法  			
				Socket s = null;
				DataOutputStream dout = null;
				DataInputStream din = null;
				try
				{
					//Thread.sleep(5000);//运行5秒后关闭对话框
					s = new Socket("192.168.1.101",8888);//指定服务器
					dout = new DataOutputStream(s.getOutputStream());//打印输出流
					din = new DataInputStream(s.getInputStream());
					//BufferedReader buf =new BufferedReader(
					//new InputStreamReader(client.getInputStream()));//缓冲区读取
					dout.writeBytes("dl:"+username.getText().toString()+"|"+
							password.getText().toString()+"|");//发送用户名、密码
					//Thread.sleep(5000);//等待
					String msg = din.readLine();//读取返回的数据
					SKA3000.this.info.setText(din.readLine());
					if(msg.startsWith("dlfh:"))
					{//收到登录返回信息
						msg=msg.substring(5);
						String para[]=msg.split("|");
						if(para[0]=="1")
						{
							Intent it  = new Intent(SKA3000.this,BaiduMapActivity.class);//实例化Intent
							SKA3000.this.startActivityForResult(it,1);//启动Activity
						}
						else if(para[0]=="0")
						{//登录失败
							Toast.makeText(SKA3000.this, "用户名或密码错误!", Toast.LENGTH_LONG).show();
						}
					}
					
				}
				catch(Exception e)
				{//捕获异常
					e.printStackTrace();//打印异常	
				}
				finally 
				{//使用finally保证之后的语句一定被执行
					try
					{
						if(din != null)
						{
							din.close();
							din = null;
						}
					}
					catch(Exception e)
					{
						e.printStackTrace();
					}
					try
					{
						if(dout != null)
						{
							dout.close();
							dout = null;
						}                                                       
					}
					catch(Exception e)
					{
						e.printStackTrace();
					}
					try
					{
						if(s != null)
						{
							s.close();
							s = null;
						}                                                       
					} 
					catch(Exception e)
					{
						e.printStackTrace();
					}
					//myDialog.dismiss();
				}
			}
		}
		.start();//线程启动
			}
		}
	}
西安-防盗定位(258472152) 13:37:32服务器发的数据怎么收不到

你可能感兴趣的:(代码)