1,502
社区成员
发帖
与我相关
我的任务
分享
Dim msgBytes() As Byte
Dim k As Long
ReDim msgBytes(bytesTotal - 1)
Winsock1.GetData msgBytes
'--- 串接包
For k = 0 To bytesTotal - 1
coll.Add msgBytes(k)
LenCurMsg = LenCurMsg + 1
Next
Do While (LenCurMsg > 12) '读完整个串接包。 一个完整包至少>12bit
'--- 取临界第1条包长指定的数据
Dim packSize As Long, tmpMsgBytes() As Byte
Dim tmpMsg As String
packSize = coll(4) * 256 ^ 3 + coll(3) * 256 ^ 2 + coll(2) * 256 + coll(1)
If packSize > LenCurMsg Then
WriteLog ("!数据不够包头指定的长度,继续串接下一包")
Exit Sub
End If
'--- 读第1个 删第1个。
ReDim tmpMsgBytes(packSize + 4 - 1)
For k = 0 To packSize + 4 - 1
If k > 11 Then '除开包头信息 前12bit (0-11)
tmpMsgBytes(k - 12) = coll(1)
End If
coll.Remove 1
LenCurMsg = LenCurMsg - 1
Next
'--- 转码
tmpMsg = DecodeToBytes(tmpMsgBytes)
WriteLog ("串包剩余大小" & LenCurMsg & " , 本条消息大小" & k & ", 内容:" & tmpMsg)
’DoEvents ‘这里时间久了,会出现堆栈溢出,不解!!!不过影响不大。暂时用resume next解决
Loop
再次感谢 Runnerchin
Dim msgBytes() As Byte, msg As dataStrc
ReDim msgBytes(bytesTotal - 1)
Winsock1.GetData msgBytes
'--- 串接包
ReDim Preserve Collection(LenCurMsg + bytesTotal - 1)
CopyMemory Collection(LenCurMsg), msgBytes(0), bytesTotal
LenCurMsg = LenCurMsg + bytesTotal
Do While (LenCurMsg > 0)
'--- 从串接包读取包头指定的大小,解码
Dim packSize As Long
packSize = Collection(3) * 256 ^ 3 + Collection(2) * 256 ^ 2 + Collection(1) * 256 + Collection(0)
If LenCurMsg < packSize Then
WriteLog ("!小于包头指定大小,跳出")
Exit Sub
End If
ReDim tmpMsgBytes(packSize + 4 - 1) As Byte
CopyMemory tmpMsgBytes(0), Collection(0), packSize + 4
msg = UnpackMsg(tmpMsgBytes)
WriteLog ("从串接包(" & UBound(Collection) + 1 & ")取数据(" & packSize + 4 & "),内容:" & msg.content)
'--- 从串接包中移除已读数据
LenCurMsg = LenCurMsg - (packSize + 4)
If LenCurMsg = 0 Then
ReDim Collection(0)
WriteLog ("串接包=0")
Else
CopyMemory Collection(0), Collection(packSize + 4), LenCurMsg
ReDim Preserve Collection(LenCurMsg - 1)
End If
Loop
Private Sub WriteLog(msg As String)
'把焦点移到最后,方便观察
T1.Text = T1.Text & Format(Now, "yyyy-MM-dd HH:mm:ss") & vbTab & msg & vbCrLf & vbCrLf
T1.SelStart = Len(T1) - 1
If Len(T1) > 20000 Then T1.Text = ""
End Sub
2017-09-07 22:46:31 --> LOGIN REQUEST
2017-09-07 22:46:31 * MSG SENT COMPLETE
2017-09-07 22:46:31 <-- MSG RECEIVED
长度:238Bytes
消息内容: type@=loginres/userid@=0/roomgroup@=0/pg@=0/sessionid@=0/username@=/nickname@=/live_stat@=0/is_illegal@=0/ill_ct@=/ill_ts@=0/now@=0/ps@=0/es@=0/it@=0/its@=0/npv@=0/best_dlev@=0/cur_lev@=0/nrc@=1651333632/ih@=0/sid@=70223/sahf@=0/
2017-09-07 22:46:32 --> JOIN
2017-09-07 22:46:32 * MSG SENT COMPLETE
2017-09-07 22:46:41 <-- MSG RECEIVED
长度:206Bytes
消息内容: type@=spbc/sn@=VVu的小跟班/dn@=VictorRiaVVu/gn@=火箭/gc@=1/drid@=2688739/gs@=5/gb@=0/es@=1/gfid@=196/eid@=143/bgl@=3/ifs@=0/rid@=244548/gid@=0/bid@=30125_1504795602_1153/sid@=11139172/cl2@=0/
2017-09-07 22:46:43 <-- MSG RECEIVED
长度:293Bytes
消息内容: type@=chatmsg/rid@=244548/ct@=1/uid@=42494976/nn@=无趣逗哥/txt@=进城了/cid@=9f0f98ac32c4463f0061010000000000/ic@=avanew@Sface@S201704@S18@S12@S739b682ec1e837792ef658ccd1d3b5af/level@=17/sahf@=0/bnn@=/bl@=0/brid@=0/hc@=/el@=eid@AA=1500000113@ASetp@AA=1@ASsc@AA=1@ASef@AA=0@AS@S/
2017-09-07 22:46:50 <-- MSG RECEIVED
长度:255Bytes
消息内容: type@=chatmsg/rid@=244548/ct@=1/uid@=85641846/nn@=765235626/txt@=倒奶现在播的什么?/cid@=9f0f98ac32c4463f5c61010000000000/ic@=avanew@Sface@S201704@S17@S07@S85e270c8a6961714ecb4b8231146e44c/level@=22/sahf@=0/bnn@=/bl@=0/brid@=0/hc@=/el@=/
2017-09-07 22:46:51 <-- MSG RECEIVED
长度:343Bytes
消息内容: type@=chatmsg/rid@=244548/ct@=1/uid@=40457391/nn@=霸气的加菲猫/txt@=流弊/cid@=9f0f98ac32c4463f6561010000000000/ic@=avanew@Sface@S201705@S13@S01@Sef10f63e4acdf2bdda0eaaf535d5c974/level@=27/sahf@=0/bnn@=叶灬子/bl@=11/brid@=244548/hc@=01c71d57378b57aa3394a48356270b6b/el@=eid@AA=1500000113@ASetp@AA=1@ASsc@AA=1@ASef@AA=0@AS@S/
2017-09-07 22:46:53 <-- MSG RECEIVED
长度:340Bytes
消息内容: type@=chatmsg/rid@=244548/uid@=25258628/nn@=我爱单色凌4/txt@=到哪里了/cid@=9f0f98ac32c4463f7761010000000000/ic@=avanew@Sface@S201708@S02@S21@S1ad33029efde508c66b64c30b473d13b/level@=16/sahf@=0/bnn@=叶灬子/bl@=7/brid@=244548/hc@=01c71d57378b57aa3394a48356270b6b/el@=eid@AA=1500000113@ASetp@AA=1@ASsc@AA=1@ASef@AA=0@AS@S/
2017-09-07 22:46:53 <-- MSG RECEIVED
长度:64Bytes
消息内容: rid@=244548/sc@=5800/sctn@=0/rid@=-1/type@=qausrespond/
2017-09-07 22:46:54 <-- MSG RECEIVED
长度:261Bytes
消息内容: type@=chatmsg/rid@=244548/ct@=1/uid@=38202744/nn@=九龙湖广州户外娱乐/txt@=鬼子进城了/cid@=9f0f98ac32c4463f9a61010000000000/ic@=avanew@Sface@S201702@S21@S01@Sf29c2c7ef9363397b2835180f265d18b/level@=15/sahf@=0/bnn@=/bl@=0/brid@=0/hc@=/el@=/
2017-09-07 22:46:55 <-- MSG RECEIVED
长度:209Bytes
消息内容: type@=spbc/sn@=等一个天气晴/dn@=ASMR猫心儿/gn@=火箭/gc@=1/drid@=2098162/gs@=5/gb@=0/es@=1/gfid@=196/eid@=143/bgl@=3/ifs@=0/rid@=244548/gid@=0/bid@=30027_1504795616_1566/sid@=1576557/cl2@=0/
2017-09-07 22:46:58 <-- MSG RECEIVED
长度:374Bytes
消息内容: type@=chatmsg/rid@=244548/ct@=1/uid@=29049637/nn@=果果淘之妖妖/txt@=阿科 骑慢点 看你直播两年了/cid@=9f0f98ac32c4463fc561010000000000/ic@=avanew@Sface@S201706@S02@S10@S79d2db43a941dd6d25ce6d70734e486a/level@=21/sahf@=0/bnn@=神刀門/bl@=6/brid@=287471/hc@=4c586e56a669d6d26e279b5d3b9968e0/el@=eid@AA=1500000113@ASetp@AA=1@ASsc@AA=1@ASef@AA=0@AS@S/
2017-09-07 22:47:01 --> KEEPALIVE PACKAGE
2017-09-07 22:47:01 * MSG SENT COMPLETE
2017-09-07 22:47:01 <-- MSG RECEIVED
长度:20Bytes
消息内容: type@=mrkl/
2017-09-07 22:47:11 <-- MSG RECEIVED
长度:64Bytes
消息内容: rid@=244548/sc@=5800/sctn@=0/rid@=-1/type@=qausrespond/
Public Type dataStrc
len1 As Long
len2 As Long
smsType As Integer
tmpstr1 As Byte
tmpstr2 As Byte
content(1023) As Byte
End Type