【发布时间】:2014-01-08 13:28:39
【问题描述】:
我正在创建一个应用程序,其中包括客户端和代理服务器应用程序。两个应用程序都使用 winsock 控件。我正在使用 IP 地址将客户端连接到服务器。服务器应用程序有问题。它只显示内部我不想要的IP地址,我想要的是外部IP地址,即Wan 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
【问题讨论】: