用VB.net调用我自己写的异步多线程socket库发送数据,作为物联网设备上应用。
Public Class Form1
Private Declare Function CommStackInit Lib "EasyAsyncStack.dll" (ByVal a As Integer, ByVal b As Integer) As Integer
Private Declare Function ES_ConnToServer Lib "EasyAsyncStack.dll" (ByVal ip As String, ByVal b As Integer) As Integer
Private Declare Function SendCollectorText Lib "EasyAsyncStack.dll" (ByVal handle As Integer, ByVal value As String, ByVal len As Integer) As Integer
Dim m_iSocketHandle As Integer
'SendCollectorText(long dwKeyAdpHandler, char* pMsgData, short sDataLen)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 连接服务器.Click
Dim res As Integer
res = CommStackInit(10, 100)
m_iSocketHandle = ES_ConnToServer("127.0.0.1", 8090)
'SendCollectorText(m_iSocketHandle, "xiaoyu@998", strlen("xiaoyu@998"));
SendCollectorText(m_iSocketHandle, "xiaoyu@999", 10)
SendCollectorText(m_iSocketHandle, "this is a text", Len("this is a text"))
'这里长度要指定要发送的字符串的真实长度
SendCollectorText(m_iSocketHandle, "19中国长城1000", 20)
SendCollectorText(m_iSocketHandle, "中国长城2002", 20)
SendCollectorText(m_iSocketHandle, "中国长城8008", 20)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SendCollectorText(m_iSocketHandle, "那是一个好消息@@88", 28)
End Sub
End Class