发送方发送
stTemp = "K01#192.168.107.31#0016"
stTemp = strEncrypt(stTemp) '加密
Winsock1.SendData stTemp
接受方
Winsock1.GetData rec, vbString
'解密
rec = strDecryption(rec)
最后rec是乱吗,rec不等于stTemp
如在本程序rec = strDecryption(strEncrypt(stTemp)),rec=stTemp 。是怎么回事?怎么解决?谢谢
'字符串加密
Public Function strEncrypt(stTemp As String) As String
Dim DataBuffer() As Byte
Dim I As Integer
DataBuffer = stTemp
For I = 0 To UBound(DataBuffer)
If DataBuffer(I) = 255 Then
DataBuffer(I) = 0
Else
DataBuffer(I) = DataBuffer(I) + 1
End If
Next I
strEncrypt = DataBuffer
End Function
'字符串解密
Public Function strDecryption(stTemp As String) As String
Dim DataBuffer() As Byte
Dim I As Integer
DataBuffer = stTemp
For I = 0 To UBound(DataBuffer)
If DataBuffer(I) = 0 Then
DataBuffer(I) = 255
Else
DataBuffer(I) = DataBuffer(I) - 1
End If
Next I
strDecryption = DataBuffer
End Function
stTemp = "K01#192.168.107.31#0016"
stTemp = strEncrypt(stTemp) '加密
Winsock1.SendData stTemp
接受方
Winsock1.GetData rec, vbString
'解密
rec = strDecryption(rec)
最后rec是乱吗,rec不等于stTemp
如在本程序rec = strDecryption(strEncrypt(stTemp)),rec=stTemp 。是怎么回事?怎么解决?谢谢
'字符串加密
Public Function strEncrypt(stTemp As String) As String
Dim DataBuffer() As Byte
Dim I As Integer
DataBuffer = stTemp
For I = 0 To UBound(DataBuffer)
If DataBuffer(I) = 255 Then
DataBuffer(I) = 0
Else
DataBuffer(I) = DataBuffer(I) + 1
End If
Next I
strEncrypt = DataBuffer
End Function
'字符串解密
Public Function strDecryption(stTemp As String) As String
Dim DataBuffer() As Byte
Dim I As Integer
DataBuffer = stTemp
For I = 0 To UBound(DataBuffer)
If DataBuffer(I) = 0 Then
DataBuffer(I) = 255
Else
DataBuffer(I) = DataBuffer(I) - 1
End If
Next I
strDecryption = DataBuffer
End Function
'接收来自客户端的数据
Winsock1.GetData Bytedata(), vbByte
然后处理bytedata数组中的数据。
stTemp = "K01#192.168.107.31#0016"
Winsock1.SendData stTemp
服务端用
Dim Bytedata() As Byte
Winsock1.GetData Bytedata(), vbByte
rec = Bytedata这里rec=か??????????是乱码哟,没有上面说到的加密。
Dim Str As String Winsock1.GetData Bytedata(), vbByte or vbArray
Str=VBA.StrConv(Bytedata,vbUnicode)
如果我发送的字符串是很长会分几次收到吗?
Winsock1.SendData stTemp
收到的Winsock1.GetData stTemp2
stTemp 是不是一定等于stTemp2 ?会不会出现几个stTemp2加起来才等于stTemp ?
我用发送
stTemp = "K01#192.168.17.31#00160"
stTemp = strEncrypt(stTemp) '加密
Winsock1.SendData stTemp
接收 Dim Bytedata() As Byte
Dim rec As String
Winsock1.GetData Bytedata(), vbByte Or vbArray
rec = VBA.StrConv(Bytedata, vbUnicode)
'解密
rec = strDecryption(rec)
收到第一个rec=ō??????????????????????
解密后是rec=L^^^^^^^^^^^^^^^^^^^^^^
Str=VBA.StrConv(Bytedata,vbUnicode) 之类的处理?才发送?
怎么判断全部接受完成?我调都是这边一发送,另一边在Winsock1.GetData Bytedata(), vbByte Or vbArray 后一句中断检查,不加密的收到的和发的一样,加密的解密后都是乱吗