delphi中通过socket向服务端传值,从服务端返回来的值如果是多次返回的不同值,在客户端应该怎么获取
从服务端如果要先返回一个状态值A(4字节),在客户端通过判断A是否满足条件,如果满足,在返回一个事务值B(72字节),不满足就报异常,那我应该在客户端怎么获取A和B?通过...
从服务端如果要先返回一个状态值A(4字节),在客户端通过判断A是否满足条件,如果满足,在返回一个事务值B(72字节),不满足就报异常,那我应该在客户端怎么获取A和B?通过字节来判断吗?
展开
若以下回答无法解决问题,邀请你更新回答
1个回答
展开全部
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;
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;
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询