我是刚学习编程的,学了VB和SQL server 老师要我们做一个基于数据库的QQ,在做的过程中遇到了一个问题。
是这样的,我在数据库中建立了3张表 一张uses表,字段有uses_Name,uses_Num,uses_Password,uses_head(头像号),
一张qq_Temp 表,字段有ud_Ip,ud_Port,ud_Num 用来记录上线人的IP,端口,QQ号,当他下线时就将其信息删掉,
一张好友表fri,字段有me_QQ,friend_QQ 用来保存好友的号 以便在上线时找到自己的好友。
我就是在上线这块遇到问题,我有2个好友,我上线时他们不在线 所以他们在我QQ上就显示暗色图标,但是代码有点问题,望指教!!!谢谢!!!
服务器代码于下:
ElseIf message(0) = "给我好友" Then 'IP 端口 自己的QQ
Dim intFri As Integer
Dim intQQ_temp As Integer
'Dim strinfo As String
'Dim varInfo123 As Variant
Dim blnHave As Boolean '判断是否在线
blnHave = False
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open "select * from QQ_temp", cn, adOpenDynamic, adLockBatchOptimistic, adCmdText
For intQQ_temp = 0 To rs.RecordCount - 1 Step 1
If message(3) = rs.Fields(2) Then '找到自己
For intI = 1 To intPeople Step 1 '遍历在线数组
If rs.Fields(2) = strNum(intI) Then '找到号码
blnHave = True '找到
wskServer.RemoteHost = message(1)
wskServer.RemotePort = message(2)
wskServer.SendData "好友信息" & "*" & strIP(intI) & "*" & strPort(intI) & "*" & strNum(intI) _
& "*" & strName(intI) & "*" & intHeadall(intI) & "*" & 1
'好友的IP,端口,号码,名字,头像号,状态1--表示在线
wskServer.RemoteHost = strIP(intI) '指定好友的网陆窗体
wskServer.RemotePort = strPort(intI)
wskServer.SendData "好友上线" & "*" & message(1) & "*" & message(2) & "*" & message(3)
'IP 端口 QQ
Exit For '退出For循环
End If
Next intI
If blnHave = True Then '没找到
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open "select * from fri", cn, adOpenDynamic, adLockBatchOptimistic, adCmdText
For intFri = 0 To rs.RecordCount - 1 Step 1
If rs.Fields(1) <> "" Then '未在线的好友号
If rs.State = adStateOpen Then
rs.Close
End If
rs.Open "select * from uses", cn, adOpenDynamic, adLockBatchOptimistic, adCmdText
If rs.Fields(1) = message(3) Then
wskServer.RemoteHost = message(1)
wskServer.RemotePort = message(2)
wskServer.SendData "好友信息" & "*" & "" & "*" & "" & "*" & message(3) & "*" & _
rs.Fields(3) & "*" & 0
'表示好友不在线所以其 IP 和 端口 为空 ,QQ号,头像号,0表示不在线
'rs.MoveNext
End If
End If
rs.MoveNext
Next intFri
End If
End If
rs.MoveNext
Next intQQ_temp
客户端代码是:
......................................................
wsk5.SendData "给我好友" & "*" & wsk5.LocalIP & "*" & wsk5.LocalPort & "*" & lngNum '发送 IP 端口 自己的QQ
........................................................
从服务器接收的消息(好友不在线时)
ElseIf message(0) = "好友下线" Then '号码
For intI = 1 To intFriend Step 1
If strNum(intI) = message(1) Then '找到下线好友
pit.AddImageList strName(intI), App.Path & "/face/" & intHeadall(intI) & "b.bmp", True, intI - 1
strIP(intI) = ""
strPort(intI) = ""
blnupordown(intI) = False
End If
Next intI
主要看服务器的代码