关于VB通信收发数据程序的问题,请求帮助(使用WINSOCK控件的),谢谢大家
大家好:我编了个VB 的网络双向通讯程序(通信的另一端是一个具有固定IP的移动终端,IP 和端口我已经在属性里设定了),但是编译时出现错误,错误如下 : THE ADDRESS IS A BROADCAST ADDRESS,AND THE FLAG IS NOT SET.程序如下:(希望高手帮忙,有对这方面比较了解的,麻烦你留言或留下QQ号,不胜感激)
Private Sub Form_Load()
Dim ConnectFlag As Boolean '设置判断是否连接标志
ConnectFlag = False
End Sub
-----------------------------------------------------------------------------------------------------------------------------
Private Sub Winsock1_Close()
Winsock1.Close
Do
DoEvents
Loop Until Winsock1.State = sckClosed
ConnectFlag = False
End Sub
-----------------------------------------------------------------------------------------------------------------------------
Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Not ConnectFlag Then
Winsock1.Close
Winsock1.Connect
Do
DoEvents
Loop Until Winsock1.State = sckConnected
ConnectFlag = True
End Sub
-----------------------------------------------------------------------------------------------------------------------------
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim datastr As String '存储传输过来的数据
Winsock1.GetData datastr
var1 = Mid(datastr, 17, 24)'将数据存入数据库
var2 = Mid(datastr, 25, 32)
var3 = Mid(datastr, 33, 40)
var4 = Mid(datastr, 41, 48)
var5 = Mid(datastr, 49, 56)
var6 = Mid(datastr, 57, 64)
var7 = Mid(datastr, 65, 72)
var8 = Mid(datastr, 73, 80)
da1.Text = var1
da2.Text = var2
da3.Text = var3
da4.Text = var4
da5.Text = var5
da6.Text = var6
da7.Text = var7
da8.Text = var8
Data1.Recordset.AddNew
Data1.UpdateRecord
Data1.Recordset.Bookmark = Data1.Recordset.LastModified
Data1.Refresh
end sub
-----------------------------------------------------------------------------------------------------------------------------
Private Sub xpcmdbutton1_Click() '发送数据的指令
Dim cmdstr1 As String
cmdstr1 = "00" '发送命令"00"
Winsock1.Connect
Winsock1.SendData cmdstr1
End Sub
---------------------------------------------------------------