我正在创建一个包含客户端和应用程序的应用程序。代理服务器应用程序。两个应用程序都使用winsock控件。我使用IP地址将客户端连接到服务器。我遇到了服务器应用程序的问题。它只显示我不想要的内部IP地址,我想要的是外部IP地址ieWan IP地址。是否可以使用winsock?如果您有示例代码,请提供。我还需要一个功能服务器,它将选择连接到服务器的客户端列表框&它将断开客户端与服务器的连接。请提供代码。一旦连接到服务器,如果用户使用Internet或任何其他程序,IP将显示为服务器的IP(如代理服务器)。 这是服务器的代码。
Option Explicit
Dim iSockets As Integer
Dim sServerMsg As String
Dim sRequestID As String
Private Sub Form_Load()
Form1.Show
lblHostID.Caption = Socket(0).LocalHostName
lblAddress.Caption = Socket(0).LocalIP
Socket(0).LocalPort = 1007
sServerMsg = "Listening to port: " & Socket(0).LocalPort
List1.AddItem (sServerMsg)
Socket(0).Listen
End Sub
Private Sub socket_Close(Index As Integer)
sServerMsg = "Connection closed: " & Socket(Index).RemoteHostIP
List1.AddItem (sServerMsg)
Socket(Index).Close
Unload Socket(Index)
iSockets = iSockets - 1
lblConnections.Caption = iSockets
End Sub
Private Sub socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
sServerMsg = "Connection request id " & requestID & " from " & Socket(Index).RemoteHostIP
If Index = 0 Then
List1.AddItem (sServerMsg)
sRequestID = requestID
iSockets = iSockets + 1
lblConnections.Caption = iSockets
Load Socket(iSockets)
Socket(iSockets).LocalPort = 1007
Socket(iSockets).Accept requestID
End If
End Sub
答案 0 :(得分:0)
我使用以下代码显示哪些客户端连接到我的服务器
Private Sub wskServer_ConnectionRequest(ByVal requestID As Long)
With wskServer
If .State <> sckClosed Then
.Close
End If
.Accept requestID
ShowData "Connection from " & .RemoteHostIP & vbCrLf, True, vbBlack
End With 'wskServer
End Sub
在我的情况下,showdata函数以监视形式显示文本,但您可以将文本写入文件或简单的msgbox