build packet header, (header + payload)
来源:互联网 发布:centos 6.7 修改ip 编辑:程序博客网 时间:2024/04/29 14:52
public class Header
{
public static byte command = 0x03;
public static byte[] uName = new byte[] { 0x20, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x01, 0x01, 0x00 };
public static byte[] password = new byte[] { 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00 };
public static byte desc;
public static byte param = 0x00;
public static byte[] seq = new byte[2];
// desc = 0x01; // change relay
// desc = 0x04; // query output
public static byte[] getChangeRelayHeader(byte[] _seq)
{
desc = 0x01; // change relay status
_seq[0] += Convert.ToByte(1);
seq[0] = _seq[0];
seq[1] = _seq[1];
List<byte> byteList = new List<byte>();
byteList.Add(command);
byteList.AddRange(uName);
byteList.AddRange(password);
byteList.Add(desc);
byteList.Add(param);
byteList.AddRange(seq);
return byteList.ToArray();
}
public static byte[] getQueryRelayHeader(byte[] _seq)
{
desc = 0x04; // query relay output status
_seq[0] += Convert.ToByte(1);
seq[0] = _seq[0];
seq[1] = _seq[1];
List<byte> byteList = new List<byte>();
byteList.Add(command);
byteList.AddRange(uName);
byteList.AddRange(password);
byteList.Add(desc);
byteList.Add(param);
byteList.AddRange(seq);
return byteList.ToArray();
}
}
}
// concat header and payload then send
/////////////////////////////////
byte[] headerBytes = Header.getChangeRelayHeader(seq);
byte[] payloadByte = Payload.getControlPayload(_channel, onOff); // channel, status
IEnumerable<byte> bytesSent = headerBytes.Concat(payloadByte); // concat header and payload
byte[] bs = bytesSent.ToArray();
socket.Send(bs, 0, 49, SocketFlags.None);
/////////////////////////////////
//byte[] header = { 0x03, // command
// 0x20, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, //user U 55 len = 23
// 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x01, 0x01, 0x00,
// 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, // passwd P 50 len = 19
// 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x50, 0x00,
// 0x01, // desc 0x01
// 0x00, // param
// 0x00, 0x00 // seq
// };
- build packet header, (header + payload)
- packet header
- TS流分析-packet header
- RTP Payload Format---RTP Header Usage
- header
- header
- header
- header
- Header();
- header
- header
- header
- RFC 3551 定义的rtp header的payload type
- 求助:如何在mvc下获取 header 以及 payload?
- Requests Header | Http Header
- Network Abstraction Layer Unit Types 以及RTP Payload Format--- NAL Unit Header Usage
- file header
- SOAP Header
- C语言之——strlen()与sizeof()
- 学习笔记 --XML
- 解读 nginx 中 chain 和 buf
- Some understanding about the MVC
- 测试&运算符
- build packet header, (header + payload)
- 求素数的几种方法
- 取消Wince App 应用启动动画和隐藏分区注册表项
- 使用Json-lib生成JSON文本
- CSS Hack
- ASP.NET AJAX 无限级 JS 树形菜单
- ural 1017 Staircases
- 理解JAVASCRIPT 中hasOwnProperty()的作用
- 2010年最后一天电脑大比拼