Mikrotik API 读取返回字节类
来源:互联网 发布:itunes怎么更新软件 编辑:程序博客网 时间:2024/06/05 07:07
byte[] tmpaa = new byte[1]; //先定义一个全局变量,保存第一次接受的字头,因为第一次接受就是一个字节,这个字节是下次接受的字头
bool isTou = false;//判断是不是第一次接受的字节,是的话,赋值给第二次接受的字节
public string Readconn(SocketAsyncEventArgs e)
{
byte[] tmpa = new byte[e.BytesTransferred];
if (tmpa.Length == 1)
{
isTou = true;
tmpaa[0] = e.Buffer[0];
return "cuowu";
}
else
{
string resRead = "";
for (int i = 1; i < e.BytesTransferred; i++)
{
if (isTou)
{
tmpa[0] = tmpaa[0];
tmpa[1] = tmpaa[0];
isTou = false;
}
tmpa[i] = e.Buffer[i - 1];
}
System.IO.Stream connection = new System.IO.MemoryStream(tmpa);
List<string> output = new List<string>();
string o = "";
byte[] tmp = new byte[4];
long count;
while (true)
{
tmp[3] = (byte)connection.ReadByte();
//if(tmp[3] == 220) tmp[3] = (byte)connection.ReadByte(); it sometimes happend to me that
//mikrotik send 220 as some kind of "bonus" between words, this fixed things, not sure about it though
if (tmp[3] == 255)
{
output.Add(o);
if (o.Substring(0, 5) == "!done" || o.Substring(0, 3) == "!re")
{
break;
}
else
{
o = "";
continue;
}
}
else
{
if (tmp[3] < 0x80)
{
count = tmp[3];
}
else
{
if (tmp[3] < 0xC0)
{
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[3], 0, 0 }, 0);
count = tmpi ^ 0x8000;
}
else
{
if (tmp[3] < 0xE0)
{
tmp[2] = (byte)connection.ReadByte();
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[2], tmp[3], 0 }, 0);
count = tmpi ^ 0xC00000;
}
else
{
if (tmp[3] < 0xF0)
{
tmp[2] = (byte)connection.ReadByte();
tmp[1] = (byte)connection.ReadByte();
int tmpi = BitConverter.ToInt32(new byte[] { (byte)connection.ReadByte(), tmp[1], tmp[2], tmp[3] }, 0);
count = tmpi ^ 0xE0000000;
}
else
{
if (tmp[3] == 0xF0)
{
tmp[3] = (byte)connection.ReadByte();
tmp[2] = (byte)connection.ReadByte();
tmp[1] = (byte)connection.ReadByte();
tmp[0] = (byte)connection.ReadByte();
count = BitConverter.ToInt32(tmp, 0);
}
else
{
//Error in packet reception, unknown length
break;
}
}
}
}
}
}
for (int i = 0; i < count; i++)
{
o += (Char)connection.ReadByte();
}
}
foreach (string item in output)
{
resRead += item;
}
//output.Clear();
return resRead;
}
}
- Mikrotik API 读取返回字节类
- MikroTik RouterOS API 操作手册
- MikroTik
- Java读取文件并返回字节数组
- 字节流_FileInputStream类读取
- 从网络字节流中读取4个字节拼装,返回long
- 同步读串口,ReadFile 返回TRUE,读取的字节数却是0 ----- 解决办法是设置超时值
- Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
- java基础--Java 字节读取流的read方法返回int的原因
- PHP如何读取JAVA用gzip压缩返回的字节流
- Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
- java基础--Java 字节读取流的read方法返回int的原因
- 浏览器无法加载本地文件,在后台读取字节流后返回给前端显示
- Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
- asm-giude阅读笔记003(ASM核心API接口和对应组件---读取字节码)
- java读取文件以字节流的形式读取 然后转化为字节流数组,最后经过SHA1加密生成返回16进制字符串存入数据库
- webservice 返回 字节流
- 读取字节的方式
- HDU-3829 Cat VS Dog
- 搜索框
- 在浏览器中和本地计算机串口进行通讯
- 并行编程方式:OpenMP + MPI +Mapreduce
- 对"ZwLoadDriver加载驱动" 的补充
- Mikrotik API 读取返回字节类
- 年终考核—-能力、态度、业绩三要素
- Oracle性能优化
- Linux Shell常用技巧
- 大一和研一
- linux下最简单的ftpget ftpput 源代码
- 梦见周罕平
- Zencart banner开发之轻松打造焦点图
- C++基本(二)零碎