在工作中需要做一个压力测试工具,在网络中发送指定内容的报文,报文内容是用Sniffer工具捕捉下来的。内容如下所示:
交易码0001发送924.txt
======================
30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20
20 20 20 20 20 20 20 20 20 30 31 37 30 32 35 30
30 30 30 30 30 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 d
30 30 30 30 30 30 30 30 30 30 30 30 30 31 37 30
30 30 30 30 31 20 20 20 20 20 20 20 20 20 20 20
20 20 20 20 20 31 30 30 30 31 32 30 30 35 30 39
……
30 30 30 31就是0001
转换代码如下:
Private Function sendFile(ByVal filename As String) As Byte()
'读要发送的文件
'将内容存于数组中byte中
Dim s As [String] '= "30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20"
Dim sp As [Char] = " "
s = TextFromFile(filename)
Dim r() As [String] = s.Split(sp)
Dim i As Integer
Dim b As Byte() = New [Byte](r.Length) {}
For i = 0 To b.Length - 1
Try
b(i) = Byte.Parse(r(i), System.Globalization.NumberStyles.HexNumber)
Catch e As Exception
'
End Try
Next
sendFile = b
End Function
'读要发送的文件
'将内容存于数组中byte中
Dim s As [String] '= "30 30 30 31 60 00 07 ff df ee 20 fc 20 20 20 20"
Dim sp As [Char] = " "
s = TextFromFile(filename)
Dim r() As [String] = s.Split(sp)
Dim i As Integer
Dim b As Byte() = New [Byte](r.Length) {}
For i = 0 To b.Length - 1
Try
b(i) = Byte.Parse(r(i), System.Globalization.NumberStyles.HexNumber)
Catch e As Exception
'
End Try
Next
sendFile = b
End Function