本人初次做局域网多客户端的一个网络程序,需要在客户端与服务器端相连时能够在服务器端实时显示IP地址和机器名,IP地址能够正常显示,但是机器名不行,请教各位高手能否耐心帮忙看下代码,红色是有问题的部分,应该如何修改可以获得客户端的机器名,谢谢了!Private Sub tcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
Dim n As Integer
Dim k As Integer
n = FirstNonConnected() '从已释放的连接中选取一个编号
If Index = 0 Then
If n = 0 Then '返回值为0时表明为新的连接
intMax = intMax + 1
Load tcpServer(intMax)
'检查控件的 State 属性是否为关闭的。
'如果不是,
'在接受新的连接之前先关闭此连接。
If tcpServer(intMax).State <> sckClosed Then
tcpServer(intMax).Close
'接受具有 requestID 参数的连接。
End If
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
If txtInfo.Text = "" Then
txtInfo.Text = "客户机" & intMax & "连接成功!"
Else
txtInfo.Text = txtInfo.Text & vbCrLf & "客户机" & intMax & "连接成功!"
End If
k = InClientInfo(tcpServer(intMax).RemoteHostIP) '查找当前连接是否在已连接列表中
If k <> 0 Then ’不是0,说明在列表中
SetMSH k, "", "", True '设置对应行为连接状态
Else
ClientNum = ClientNum + 1
ClientIP(ClientNum) = tcpServer(intMax).RemoteHostIP
ClientName(ClientNum) = tcpServer(intMax).RemoteHostName '就是这儿有问题,不知怎么改
SetMSH ClientNum, ClientName(ClientNum), ClientIP(ClientNum), True
End If
txtInfo.Text = txtInfo.Text & Now() & " " & tcpServer(intMax).RemoteHostIP & "登陆成功!" & vbCrLf
Else ’找到一个已释放的编号
If tcpServer(n).State <> sckClosed Then
tcpServer(n).Close
'接受具有 requestID 参数的连接。
End If
tcpServer(n).LocalPort = 0
tcpServer(n).Accept requestID
If txtInfo.Text = "" Then
txtInfo.Text = "客户机" & n & "连接成功!"
Else
txtInfo.Text = txtInfo.Text & vbCrLf & "客户机" & n & "连接成功!"
End If
k = InClientInfo(tcpServer(intMax).RemoteHostIP)
If k <> 0 Then
SetMSH k, "", "", True
End If
txtInfo.Text = txtInfo.Text & Now() & " " & tcpServer(intMax).RemoteHostIP & "登陆成功!" & vbCrLf
End If
MSH1.Refresh
lblConnect.Caption = "当前在线客户机总数:" & getConnectNum()
End If
End Sub
Dim n As Integer
Dim k As Integer
n = FirstNonConnected() '从已释放的连接中选取一个编号
If Index = 0 Then
If n = 0 Then '返回值为0时表明为新的连接
intMax = intMax + 1
Load tcpServer(intMax)
'检查控件的 State 属性是否为关闭的。
'如果不是,
'在接受新的连接之前先关闭此连接。
If tcpServer(intMax).State <> sckClosed Then
tcpServer(intMax).Close
'接受具有 requestID 参数的连接。
End If
tcpServer(intMax).LocalPort = 0
tcpServer(intMax).Accept requestID
If txtInfo.Text = "" Then
txtInfo.Text = "客户机" & intMax & "连接成功!"
Else
txtInfo.Text = txtInfo.Text & vbCrLf & "客户机" & intMax & "连接成功!"
End If
k = InClientInfo(tcpServer(intMax).RemoteHostIP) '查找当前连接是否在已连接列表中
If k <> 0 Then ’不是0,说明在列表中
SetMSH k, "", "", True '设置对应行为连接状态
Else
ClientNum = ClientNum + 1
ClientIP(ClientNum) = tcpServer(intMax).RemoteHostIP
ClientName(ClientNum) = tcpServer(intMax).RemoteHostName '就是这儿有问题,不知怎么改
SetMSH ClientNum, ClientName(ClientNum), ClientIP(ClientNum), True
End If
txtInfo.Text = txtInfo.Text & Now() & " " & tcpServer(intMax).RemoteHostIP & "登陆成功!" & vbCrLf
Else ’找到一个已释放的编号
If tcpServer(n).State <> sckClosed Then
tcpServer(n).Close
'接受具有 requestID 参数的连接。
End If
tcpServer(n).LocalPort = 0
tcpServer(n).Accept requestID
If txtInfo.Text = "" Then
txtInfo.Text = "客户机" & n & "连接成功!"
Else
txtInfo.Text = txtInfo.Text & vbCrLf & "客户机" & n & "连接成功!"
End If
k = InClientInfo(tcpServer(intMax).RemoteHostIP)
If k <> 0 Then
SetMSH k, "", "", True
End If
txtInfo.Text = txtInfo.Text & Now() & " " & tcpServer(intMax).RemoteHostIP & "登陆成功!" & vbCrLf
End If
MSH1.Refresh
lblConnect.Caption = "当前在线客户机总数:" & getConnectNum()
End If
End Sub
解决方案 »
- 我有1000个邮件地址,如何知道其中哪些邮件地址是无效的、或是已经作废的、或者根本发送不到的。
- 如果想向WORD 或 EXCEL中发送消息,怎样确定WORD 或 EXCEL 中的焦点?
- VB中怎么让WebBrowser只获取网页而不下载嵌入元素图片、声音、FLASH?
- 如何调用DATAGRID里面的某个方框里的内容(解决就结贴)
- 写文本文件如何控制字体大小?
- 做题:Print #1, Chr(27) + Chr(74) + Chr(100) + Chr(27) + Chr(74) + Chr(100)是什么意思,
- 关于重画控件时的闪烁问题
- 求一VB分解数的算法
- 为何windows启动完成后自动打开“我的电脑---c:\"
- VB做写字板 段落代码
- VB能做成B/S模式吗?
- listview权限设置
Private Sub tcpClient_Connect()
If txtOutput.Text = "" Then
txtOutput.Text = "连接成功!"
Else
txtOutput.Text = txtOutput.Text & vbCrLf & "连接成功!"
End If
txtHost.Enabled = False
cmdConnect.Enabled = False ’禁止再连接
cmdDisConnect.Enabled = True '允许断开
tcpClient.SendData "Name:" & tcpClient.LocalHostName
End Sub在服务器这边过程tcpServer_DataArrival(Index As Integer, ByVal bytesTotal As Long)处理的结果如何才能传回到前边的过程tcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)中?