vb.net TCP协议服务端ip怎么写才能使客户端能通过公网连接进来?

服务端代码
Dim localAddr As IPAddress = ipAddress.Parse("192.168.X.X")
tlTcpListen = New TcpListener(localAddr, iPort)
这样只能在局域网内连接,要怎么样才能让客户端通过公网连接呢?
最新回答
含悦人道

2024-09-30 01:57:44

需要出口设备进行映射内部地址;或使用打洞技术穿透NAT,但使用TCP打洞非常困难。
参考
http://www.cnblogs.com/allexw/archive/2012/12/25/2832612.html


穿透NAT是非常困难的,因为NAT的过程中在出口路由器上的Port已经不是你定义的iPort了,具体是多少也不固定
有多少爱能够胡来

2024-09-30 03:29:33

Function IdCheck(s As String, birthday As String, sex As String) As Boolean
Dim code1, code2, i As Integer, n As Integer, temp As String
code1 = Split("1 0 X 9 8 7 6 5 4 3 2")
code2 = Split("7 9 10 5 8 4 2 1 6 3 7 9 10 5 8 4 2 1")
s = UCase(Trim(s))
If Len(s) = 15 Then
temp = Mid(s, 1, 6) & "19" & Mid(s, 7)
ElseIf Len(s) = 18 Then
temp = Left(s, 17)
Else
Exit Function
End If
For i = 0 To Len(temp) - 1
n = n + Mid(temp, i + 1, 1) * code2(i)
Next
n = n Mod 11
If Len(s) = 18 And code1(n) <> Right(s, 1) Then Exit Function
IdCheck = True
If Len(s) = 15 Then
birthday = Format("19" & Mid(s, 7, 6), "#0000-00-00")
sex = IIf(Right(s, 1) Mod 2 = 1, "男", "女")
Else
birthday = Format(Mid(s, 7, 8), "#0000-00-00")
sex = IIf(Mid(s, 17, 1) Mod 2 = 1, "男", "女")
End If
End Function
追问
这是什么啊