VB中发送16进制数据包?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB中发送16进制数据包?相关的知识,希望对你有一定的参考价值。
VB发送16进制数据包 使用WINSOCK进行TCP连接 连接何发送16进制数据包 我需要TCP连接 谢谢
参考技术A 发送16进制数据包跟发送String类型数据包样或者也转换成2进制发送
主要接收端对数据包处理
winsock1.sendata
"abcde"
Doevents
'里加句
winsock1.sendata
"fghij"
winsock多IP发送数据vb6
【中文标题】winsock多IP发送数据vb6【英文标题】:winsock multiple IP senddata vb6 【发布时间】:2012-10-31 06:58:38 【问题描述】:如果可以使用winsock 向不同IP 发送文本,我已经在不同的论坛中搜索了很长时间,但我找不到方法。 我尝试将两个不同的 Winsock 以相同的形式放置,但第二个 Winsock 的消息永远不会到达。 这是我的代码:
Private Sub Form_Load()
On Error Resume Next
a = bytMsg()
wsck.RemoteHost = strNombreATMMonitor2
wsck.RemotePort = vPuertoATMMonitor2
wsck.Connect
'Conectamos el segundo
Winsock1.RemoteHost = strNombreATMMonitor
Winsock1.RemotePort = vPuertoATMMonitor
Winsock1.Connect
End Sub
Private Sub wsck_Close()
On Error Resume Next
wsck.Close
End
End Sub
Private Sub wsck_Connect()
On Error GoTo Err_wsck_Connect
wsck.SendData a
End_wsck_Connect:
Exit Sub
Err_wsck_Connect:
GrabaLog "wsck_Connect", Err.Description, " " & Err.Number & " Host: " & strNombreATMMonitor
Resume End_wsck_Connect
End Sub
Private Sub wsck_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'si no es un recordatorio, lo grabo
If bytRecordatorio = 0 Then
GrabaOff strLineaComandos
End If
GrabaLog "wsck_Error", "RemoteHost" & " - " & wsck.RemoteHost & " - RemotePort - " & Trim(wsck.RemotePort), "Error = " & Trim(Number) & " - " & Description
End
End Sub
Private Sub wsck_SendComplete()
On Error GoTo Err_wsck_SendComplete
wsck.Close
'Graba en un log el mensaje de NCR pasado como parametro a ATMSpyNEW + FTP
TrazaLog "ATMMonitor1 - " & strLineaComandos
End_wsck_SendComplete:
End
Err_wsck_SendComplete:
GrabaLog "wsck_SendComplete", Err.Description, "" & Err.Number
Resume End_wsck_SendComplete
End Sub
Private Sub Winsock1_Close()
On Error Resume Next
Winsock1.Close
End
End Sub
Private Sub Winsock1_Connect()
On Error GoTo Err_Winsock1_Connect
Winsock1.SendData a
End_Winsock1_Connect:
Exit Sub
Err_Winsock1_Connect:
GrabaLog "Winsock1_Connect", Err.Description, " " & Err.Number & " Host: " & strNombreATMMonitor
Resume End_Winsock1_Connect
End Sub
Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'si no es un recordatorio, lo grabo
If bytRecordatorio = 0 Then
GrabaOff strLineaComandos
End If
GrabaLog "Winsock1_Error", "RemoteHost" & " - " & Winsock1.RemoteHost & " - RemotePort - " & Trim(Winsock1.RemotePort), "Error = " & Trim(Number) & " - " & Description
End
End Sub
有谁知道如何使用一个或两个 winsock 控件将一段文本发送到至少两个不同的 Ip (RemoteHost)?
【问题讨论】:
你肯定可以同时使用多个winsock对象。您确定有主机在监听第二个连接吗? 【参考方案1】:我创建了一个新的 VB6 项目并在 Form1 上添加了两个 Winsock 控件。即 Winsock1 和 Winsock2。然后我添加了两个文本框(仅用于测试以显示来自 Winsocks 的输入和输出)并将它们设置为允许多行。我添加了一个按钮(cmdSendData),它将向两个winsocks 发送数据。在 Form_Load 事件中,我让这两个 Winsocks 连接到我已经可以访问的公共 TelNet 服务器(您需要将 IP 地址更改为可以测试的地址)。我能够通过两个 Winsocks 发送数据(即使它们连接到同一台机器,它们的行为也不同,如果我知道我有另一个 IP 等待连接请求,可以轻松地将其中一个的 IP 更改为另一个)。
我跳过了错误处理,因为我相信您可以弄清楚该放在哪里。
Private Sub Form_Load()
Me.Winsock1.RemoteHost = "10.11.27.87"
Me.Winsock1.RemotePort = "23"
Me.Winsock1.Connect
Me.Winsock2.RemoteHost = "10.11.27.87"
Me.Winsock2.RemotePort = "23"
Me.Winsock2.Connect
End Sub
Private Sub cmdSendData_Click()
Me.Winsock1.SendData "admin" & vbCrLf
DoEvents 'This is necessary to immediatelly send the data without waiting for
' a certain buffer to be filled first
Me.Winsock2.SendData "admin" & vbCrLf
DoEvents 'same as above
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim txt As String
Me.Winsock1.GetData txt
Me.Text1.Text = Me.Text1.Text & vbCrLf & txt
End Sub
Private Sub Winsock2_DataArrival(ByVal bytesTotal As Long)
Dim txt As String
Me.Winsock2.GetData txt
Me.Text2.Text = Me.Text2.Text & vbCrLf & txt
End Sub
【讨论】:
非常感谢!!我将尝试您的代码...但是在您的示例中,remoteHost Ip 在两个示例中都是“10.11.27.87”,更改它的结果是否相同? 是的。无论是相同的IP还是不同的IP都没有关系。只要你有两个独立的连接就可以完成这项工作以上是关于VB中发送16进制数据包?的主要内容,如果未能解决你的问题,请参考以下文章