问一个弱智的问题!请给予解答!

manboo 2003-08-08 11:59:18
在协议中经常说:
包头和包体,包头和包体的概念我能够理解,但是我想知道如何将包头和包体发送出去,还还有我接收的东西如何进行解包,获得内容呢?我过去一直在作数据库相关的开发还请各位大侠给予解答,最好给个小小的例子.伪码也可以阿!
=========================================================================
此处所说的协议是指自定义的运行在TCP/IP之上的用户协议!
...全文
24 33 打赏 收藏 转发到动态 举报
写回复
用AI写文章
33 条回复
切换为时间正序
请发表友善的回复…
发表回复
manboo 2003-09-19
  • 打赏
  • 举报
回复
几位没有得到分的兄弟抱歉了!分不够了!
manboo 2003-09-19
  • 打赏
  • 举报
回复
谢谢大家!我开始分赃了!
xdyanzg 2003-08-08
  • 打赏
  • 举报
回复
很多书上都应该有的吧。
Zengqf_W 2003-08-08
  • 打赏
  • 举报
回复
我对这方面不是很了解,不过建议以看看相关方面的书
lynew 2003-08-08
  • 打赏
  • 举报
回复
up
DWGZ 2003-08-08
  • 打赏
  • 举报
回复
up
IwantFlay 2003-08-08
  • 打赏
  • 举报
回复
up
tonylk 2003-08-08
  • 打赏
  • 举报
回复
一般的网络程序发送数据单位为一个包,包的大小是固定的,即包头加包体的大小,包体是将一个完整的数据分割后某一段的数据,包头就用来定义后面跟的包体是属于哪一个数据的,以及它在整个数据中的位置,这样接收放在收到数据后就可以将整个数据拼装起来了。
对于socket来说,它是不分包头和包体的,它只知道你让它发多少数据就发多少,所以server端和client端必须有同样的包头定义。
manboo 2003-08-08
  • 打赏
  • 举报
回复
再次提一下!UP的也有分赃
manboo 2003-08-08
  • 打赏
  • 举报
回复
再提
manboo 2003-08-08
  • 打赏
  • 举报
回复
先提!
Geranium 2003-08-08
  • 打赏
  • 举报
回复
struct OnePkg
{
int msgnum;
struct bbb
{
sqlint32 sequence_number;
char timeout_stamp[27];
char message_type_identifier[5];
char primary_account_number[20];
char processing_code[7];
char amount_of_transaction[13];
char transmission_date_and_time[11];
char system_trace_audit_number[9];
char time_of_local_transaction[9];
char date_of_local_transaction[11];
char date_of_expired[5];
char date_of_settlement[11];
char merchants_type[5];
char point_of_service_entry_mode[4];
char point_of_service_condition[3];
char acquiring_institution_id_code[12];
char forwarding_institution_id_code[12];
char retrieval_reference_number[13];
char authorization_id[7];
char response_code[3];
char card_acceptor_terminal_id[12];
char card_acceptor_id[16];
char card_acceptor_name_location[41];
char addition_response_data[26];
char currency_code_of_transaction[4];
char currency_code_of_settlement[4];
char reserved_private[41];
char id_number[22];
char network_management_code[4];
char credit_number[11];
char reversal_num_of_credits[11];
char debit_number[11];
char reversal_num_of_debits[11];
char credits_amount[17];
char dedits_amount[17];
char original_data_element[43];
char message_security_code[9];
char message_authentication[9];
} msg[MSG_IN_PACKAGE];
} buffer;
MSG_IN_PACKAGE为自定义的宏,为包的总长度。
yijiansong 2003-08-08
  • 打赏
  • 举报
回复
帮你UP一下吧
corben 2003-08-08
  • 打赏
  • 举报
回复
koma2003 2003-08-08
  • 打赏
  • 举报
回复
帮你UP一下吧
naughtyboy 2003-08-08
  • 打赏
  • 举报
回复
IP分包分析
封│ |------用户数据--------------------| ↑解
包│ |--APP--|------用户数据--------------------| │包
顺│ |**TCP包头**|--------------应用数据--------------------| │顺
序↓ |&&IP包头&&|**TCP包头**|--------------应用数据--------------------| │序

各包头分析如下。

IP头
type
_iphdr = record
h_lenver : byte; //4位首部长度+4位IP版本号
tos : char; //8位服务类型TOS
total_len : char; //16位总长度(字节)
ident : word; //16位标识
frag_and_flags : word; //3位标志位
ttl : byte; //8位生存时间 TTL
proto : byte; //8位协议 (TCP, UDP 或其他)
checksum : word; //16位IP首部校验和
sourceIP : Longword; //32位源IP地址
destIP : Longword; //32位目的IP地址
end;

TCP头
type
_tcphdr=record //定义TCP首部
TCP_Sport : word; //16位源端口
TCP_Dport : word; //16位目的端口
th_seq : longword; //32位序列号
th_ack : longword; //32位确认号
th_lenres : byte; //4位首部长度/6位保留字
th_flag : char; //6位标志位
th_win : word; //16位窗口大小
th_sum : word; //16位校验和
th_urp : word; //16位紧急数据偏移量
end;
因为你已经受到数据包,按照上面的结构顺序读出数据
vargent77 2003-08-08
  • 打赏
  • 举报
回复
可能一起发也可以,不过如果掉包就问题大啦!
来个例子(仅一部分):
客户端:var
writetext:string;
..........
begin
.......
//发送的格式如<报文头><内容>(这里假设报文头只有发送人信息)
writetext:='<'+fromname.text+'>'+"<'+memsend.text+'>';
......
if ClientSocket.Active then
ClientSocket.Socket.SendText(WriteText);
.........
end;

服务器端:
for I := 1 to Length(ReadText) do
begin
X := Copy(ReadText, I, 1);
if (X = '<') then
begin
Inc(Y);//包头
if (Y = 1) then );//包头
SenderBegin := I + 1
else if (Y = 2) then //内容
MsgBegin := I + 1;
end
else if (X = '>') then
begin
if (Y = 1) then//包头
SenderLen := I - SenderBegin
else if (Y = 2) then//内容
MsgLength := I - MsgBegin;
end;
Sender := Copy(ReadText, SenderBegin, SenderLen);//包头
Msg := Copy(ReadText, MsgBegin, MsgLength);//内容
dingzhaofeng 2003-08-08
  • 打赏
  • 举报
回复
不会,来分赃的!
firetoucher 2003-08-08
  • 打赏
  • 举报
回复
不太明白你的意思,你自己定义的协议,对于用户来说是在tcp/ip以上的封装,读出和写入的算法方式都是你自己的啊,你想问什么?发送就是和其他一样的send和retrieve,发送都是以ip包的形式依次发送,你可以基于或者固定buffer来做,至于如何发送,就应该是你自己的协议的事情了。

jacket008 2003-08-08
  • 打赏
  • 举报
回复
up
加载更多回复(13)

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧