如何使Android客户端通过socket与delphi的服务端通讯

andriod代码如下
Button b_send=(Button) findViewById(R.id.send_button);
       
        b_send.setOnClickListener(new Button.OnClickListener()
        {
         @Override
         public void onClick(View arg0)
        {
          EditText e_send =(EditText) findViewById(R.id.send_edit);
          TextView t_send=(TextView) findViewById(R.id.send_textview);
          String mesg=e_send.getText().toString();
         
          try
          {
           socket=new Socket("168.0.0.205",4321);

PrintWriter out=new PrintWriter( new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
           out.println(mesg);
           out.close();   
           }


          catch (UnknownHostException e)
          {
           e.printStackTrace();
          }
          catch (IOException e)
          {
           e.printStackTrace();
          }
   }

delphi代码如下:(使用的INDY组件)
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
  wlm_buff: array[0..255] of Byte;
  wlm_char: string[255];
begin
  StrCopy(@wlm_buff[0], #0);
  if AThread.Connection.Connected then
  begin
    AThread.Connection.ReadBuffer(wlm_buff, 255);
    CopyMemory(@wlm_char, @wlm_buff[0], 255);
    Label1.Caption := wlm_char;
  end;
end;

posted @ 2016-03-16 09:51  心燃  阅读(647)  评论(0编辑  收藏  举报