发送的数据分析
ServerSocket端
record型数据
字段名 字节数 属性
Msg_Id 8 integer
Destnation_id 21 Octet String
Service_id 10 Octet String
TP_pid 1 Integer
TP_udhi 1 Integer
Msg_Fmt 1 Integer
Srcterminal_id 21 Octet String
Registered_Delivery 1 Integer
Msg_length 1 Integer
Msg_Content 1 Octet String
Reserve 8 Octet String
记录型数据依次对应以下数据
十六进制
89 5 23
59 0 0 0 05 0 0 0 17 0 0 0
//////
不用管
77 b2 1 0 2b 87 3 0
是ascii吗,不太知道
'08585'
30 38 35 38 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 00'13654668189'
31 33 36 35 34 36 36 38 31 38 39 0 0 0 0 0 0 0 0 0 004'DYTT'
44 59 54 540 0 0 0 0 0 0 0
clientServer端部分代码
type
TRecInfo = record
Total_Length : integer;
Command_ID : integer;
Sequence_ID : integer;
Msg_Id : int64;
Destnation_id : string[21];
Service_id : string[10];
TP_pid : byte;
TP_udhi : byte;
Msg_Fmt : byte;
Srcterminal_id : String[21];
Registered_Delivery : byte;
Msg_length : byte;
Msg_Content : string[20];
Reserve : string[8];
end;
procedure TShortMsgForm.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
RecInfo:^TRecInfo;
begin
RecInfo:=Pointer(socket.ReceiveText);
edit1.text:=inttostr(RecInfo^.Total_Length);
edit2.text:=inttostr(RecInfo^.Command_ID);
edit3.text:=inttostr(RecInfo^.Sequence_ID);
edit4.Text:=inttostr(RecInfo^.Msg_Id);
edit5.Text:=RecInfo^.Destnation_id;
edit6.Text:=RecInfo^.Service_id;
edit7.Text:=Inttostr(RecInfo^.TP_pid);
edit8.text:=Inttostr(RecInfo^.TP_udhi);
edit9.Text:=Inttostr(RecInfo^.Msg_Fmt);
edit10.Text:=RecInfo^.Srcterminal_id;
edit11.Text:=Inttostr(RecInfo^.Registered_Delivery);
edit12.Text:=Inttostr(RecInfo^.Msg_length);
edit13.Text:=RecInfo^.Msg_Content;
edit14.Text:=RecInfo^.Reserve;
end;
通过以上过程,integer,byte得到数据一致,而字符串得到的数据和发送的数据不一致,如何解决
ServerSocket端
record型数据
字段名 字节数 属性
Msg_Id 8 integer
Destnation_id 21 Octet String
Service_id 10 Octet String
TP_pid 1 Integer
TP_udhi 1 Integer
Msg_Fmt 1 Integer
Srcterminal_id 21 Octet String
Registered_Delivery 1 Integer
Msg_length 1 Integer
Msg_Content 1 Octet String
Reserve 8 Octet String
记录型数据依次对应以下数据
十六进制
89 5 23
59 0 0 0 05 0 0 0 17 0 0 0
//////
不用管
77 b2 1 0 2b 87 3 0
是ascii吗,不太知道
'08585'
30 38 35 38 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 00'13654668189'
31 33 36 35 34 36 36 38 31 38 39 0 0 0 0 0 0 0 0 0 004'DYTT'
44 59 54 540 0 0 0 0 0 0 0
clientServer端部分代码
type
TRecInfo = record
Total_Length : integer;
Command_ID : integer;
Sequence_ID : integer;
Msg_Id : int64;
Destnation_id : string[21];
Service_id : string[10];
TP_pid : byte;
TP_udhi : byte;
Msg_Fmt : byte;
Srcterminal_id : String[21];
Registered_Delivery : byte;
Msg_length : byte;
Msg_Content : string[20];
Reserve : string[8];
end;
procedure TShortMsgForm.ClientSocketRead(Sender: TObject;
Socket: TCustomWinSocket);
var
RecInfo:^TRecInfo;
begin
RecInfo:=Pointer(socket.ReceiveText);
edit1.text:=inttostr(RecInfo^.Total_Length);
edit2.text:=inttostr(RecInfo^.Command_ID);
edit3.text:=inttostr(RecInfo^.Sequence_ID);
edit4.Text:=inttostr(RecInfo^.Msg_Id);
edit5.Text:=RecInfo^.Destnation_id;
edit6.Text:=RecInfo^.Service_id;
edit7.Text:=Inttostr(RecInfo^.TP_pid);
edit8.text:=Inttostr(RecInfo^.TP_udhi);
edit9.Text:=Inttostr(RecInfo^.Msg_Fmt);
edit10.Text:=RecInfo^.Srcterminal_id;
edit11.Text:=Inttostr(RecInfo^.Registered_Delivery);
edit12.Text:=Inttostr(RecInfo^.Msg_length);
edit13.Text:=RecInfo^.Msg_Content;
edit14.Text:=RecInfo^.Reserve;
end;
通过以上过程,integer,byte得到数据一致,而字符串得到的数据和发送的数据不一致,如何解决
解决方案 »
- Qreport预览时窗体如何最大化?
- 关于并发性问题
- 如何设置文件共享(Delphi7+WinXP)
- 如何在继承的窗体中显示祖先窗体上的控件
- 请问哪里能下载 Delphi7 studio 支持Microsoft .NET ,是Borland 2002-08-06发布的?
- 如何给PCHAR类型的变量赋上16进制的数据?
- 我使用odbc连接mysql,我想获得所有的数据表名称,应该怎么做呢
- delphi2007 如何安装indy9.0
- 为什么Delphi7中无法使用writeIn这个函数??
- 请问个位大虾那有ADO的资料下载
- 怎样让ListBox变成透明的,如果需要编程...
- 问个WebBrowser的另类问题
8bit ==> Byte or Char
16bit ==> Word
32bit ==> Integer or Cardinal
64bit ==> Int64还有定义时,结构里面的域一定要和C/C++一样,不能顺序不同
Data: TRecvInfo;
begin
FillChar(Data, SizeOf(Data), 0);
Socket.ReceiveBuf(Data, SizeOf(Data));
ShowMessage(Data.Msg_ID);
end;
字段名 字节数 属性
Msg_Id 8 integer
Destnation_id 21 Octet String
Service_id 10 Octet String
TP_pid 1 Integer
TP_udhi 1 Integer
Msg_Fmt 1 Integer
Srcterminal_id 21 Octet String
Registered_Delivery 1 Integer
Msg_length 1 Integer
Msg_Content 1 Octet String
Reserve 8 Octet String
你看C是怎么定义的?
或者你把C的定义贴出来
如下:
procedure Excode;
var
...
Data:string[21];
begin
...
for i:=0 to 20 do
Data[i]:=DateRev[length of Msg_id-1 to length of Msg_Id-1];
....
//以下的一样
end;
Data[i]:=DateRev[length of Msg_id-1 + length of Msg_Id-1];
关键是serversocket也是我用delphi定义的,用ReceiveBuf、ReceiveText都没问题,可serversocket是用C写的, 而且发送的一堆,ascii,十六进制,什么的,接收就有问题了
记录型数据依次对应以下数据
十六进制
89(10进制) 5(10进制) 23(10进制)
59 0 0 0(16进制) 05 0 0 0(16进制) 17 0 0 0(16进制)
//////
不用管
77 b2 1 0 2b 87 3 0
是ascii吗,不太知道
'08585'(10进制)
30 38 35 38 35 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 00'13654668189'
31 33 36 35 34 36 36 38 31 38 39 0 0 0 0 0 0 0 0 0 004'DYTT'
44 59 54 54(ascii对应'DYTT')0 0 0 0 0 0 0 0
改成
TRecInfo = packed record
改成packed,好想对了,我再看看
大多数,接收的都对了,可还有个别的有问题,说明这方法是可行的